MVC3----渲染輔助方法

來源:互聯網
上載者:User

標籤:action   控制器   school   null   

--------------Html.ActionLink

@Html.ActionLink("當前控制器的Index頁面", "Index")

@Html.ActionLink("SchoolType控制器的Index頁面", "Index", "SchoolType")

@Html.ActionLink("當前控制器的Index頁面", "Index", new { ID=1}) //傳遞參數


--------------Html.RouteLink(不接收控制器名稱和操作名稱)

@Html.RouteLink("當前控制器的Index頁面", new { action = "Index" })






--------------Url.Action

<!--    操作方法名稱 ,控制器名稱,參數,                  協議-->

@Url.Action("Index", "Test", new { schooltype = "school" }, null)

渲染:

/Test?schooltype=school 


--------------Url.RouteUrl

路由名稱

@Url.RouteUrl("Default")

渲染:

/test/Edit/1 


--------------Url.Content(重要,把相對路徑轉換為絕對路徑)

@Url.Content("~/Script/jquery.js")

渲染:

/Script/jquery.js 





--------------Html.Partial(分布視圖,方便型)

尋找視圖的路徑:

1,當前控制器所指向的視圖

2,~/Views/Shared/路徑下面

--控制器代碼:

public ActionResult Msg()

{

    return PartialView();

}

--視圖代碼:

@Html.Partial("Msg")


--------------Html.RenderPartial(分布視圖,較好的效能)

(它直接寫入相應流)

--控制器代碼:

public ActionResult Msg()

{

    return PartialView();

}

--視圖代碼:

@{Html.RenderPartial("Msg")}


--------------Html.Action(建立子視圖,方便型)

ChildActionOnly:只能嵌入頁面(當做子視圖)

--控制器代碼:

[ChildActionOnly]

public ActionResult Msg()

{

    return PartialView();

}

--視圖代碼:

     方法名稱    參數

@Html.Action("Edit", new { ID=1}) 


--------------Html.RenderAction(建立子視圖,較好的效能)

ChildActionOnly:只能嵌入頁面(當做子視圖)

--控制器代碼:

[ChildActionOnly]

public ActionResult Msg()

{

    return PartialView();

}

--視圖代碼:

     方法名稱    參數

@{Html.Action("Edit", new { ID=1});}


本文出自 “程式猿的家--Hunter” 部落格,請務必保留此出處http://962410314.blog.51cto.com/7563109/1598919

MVC3----渲染輔助方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.