html.renderpartial 命名空间,@Html.Partial @Html.RenderPartial @Html.Action @Html.RenderAction使用...

這樣寫效能較差,不推薦使用@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" });

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值