這樣寫效能較差,不推薦使用@Html.Partial("View")
//PartialViewName,而如果是使用其他目錄(例如 ~/Views/Shared/)的 Partial View 檔案,則可以使用檔案路徑。
@Html.Partial("~/Views/Shared/View")
這樣寫效能較Html.Partial好,建議使用!@{
Html.RenderPartial("View");
}
@{
Html.RenderPartial("~/Views/Shared/View")
}
如果只要顯示畫面呈顯畫面的廣告之類可以使用Partial因為不會從Server要資料。
Profession ASP.NET MVC 4裡面另外有提到,若是以效能來說,Html.RenderPartial會比Html.Partial來得好些,因為是在內部直接寫入到 ViewPage 的 Output Stream 裡,而Html.Partial則因為輸出MvcHtmlString,ViewPage於Render時會需要另外去處理。
介紹Html.Action & Html.RenderAction使用
@[email protected](Controller)進行一些Server端的程式碼或是取得資料庫的資料,然後再輸出而已@{
Html.RenderAction("GetActionRender", "Partial", new { vlue = "777" });
}
@Html.Action("GetActionRender", "Partial", new { value = "777" })
[email protected]@[email protected]:
[email protected]@Html.Action,不能使用@Html.RenderAction,網路上的說明是因為@Html.Action是直接輸出string,不是mvchtmlstring, 因此無法使用。
結論總結:
Html.Action() – Outputs string
Html.RenderAction() – Renders directly to response//Response stream is the better performance from string output.
@section contentSection
{
@Html.Action("GetActionRender", "Partial", new { stringValue = "777", intValue = 888 });
//無法使用Html.RenderAction,網路上說是因為他是直接輸出string,不是mvchtmlstring, 因此無法使用
Html.RenderAction("GetActionRender", "Partial", new { value = "777" });
}