在循环中调用 RenderPartial:尽可能避免?
通常最好避免在循环情况下调用渲染部分...
<% foreach (var buildingRate in locationBuildingRate.BuildingRates)
{
Html.RenderPartial("LocationBuildingRate", buildingRate);
}
%>
而是允许渲染在部分内部循环?第二种方法是否可以避免大量开销?
Html.RenderPartial("LocationBuildingRate", locationBuildingRate.BuildingRates);
Is it generally best to avoid calling to render partial in a loop situation...
<% foreach (var buildingRate in locationBuildingRate.BuildingRates)
{
Html.RenderPartial("LocationBuildingRate", buildingRate);
}
%>
And instead allow the rendering to loop inside the partial? Does this second way avoid a lot of overhead?
Html.RenderPartial("LocationBuildingRate", locationBuildingRate.BuildingRates);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。在循环内调用渲染部分会为每次运行请求渲染引擎。最好采用第二种方法,在部分内部循环。
Yes. Calling a render partial inside a loop would request the rendering engine for each run. Better to do the second approach where you loop inside the partial..
处理此问题的最佳方法是利用 EditorTemplates 和 DisplayTemplates,它们基本上渲染部分内容,但成本较低。
The best way to handle this is to leverage EditorTemplates and DisplayTemplates, which basically renders a partial but is less expensive.