1

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);
CRice
  • 12,279
  • 7
  • 57
  • 84

2 Answers2

1

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..

sajoshi
  • 2,733
  • 1
  • 18
  • 22
0

The best way to handle this is to leverage EditorTemplates and DisplayTemplates, which basically renders a partial but is less expensive.

smartcaveman
  • 41,281
  • 29
  • 127
  • 212
  • Isn't it just a matter of moving the loop code to within the partial? What benefits do the templates provide? – CRice Mar 04 '11 at 05:00
  • http://stackoverflow.com/questions/5037580/asp-net-mvc-3-partial-vs-display-template-vs-editor-template/ – Ciarán Bruen Sep 11 '12 at 15:59