I just happen to check the performance of an ASP.NET MVC application we are building. I was going to insert a partial view into a loop, and just out of curiosity I checked how l
I've just changed a MVC2 view from using a partial view in a loop to a single view, i.e. :
foreach(var a in items)
{
<%: Html.Partial("SomePartialView",a) %>
}
Where SomePartialView contains the code to render a single row in a table, e.g. :
Model.Name Model.description
to :
foreach(var a in items)
{
a.Name a.description
}
for a view rendering 900 rows the page render time went down from 5+ minutes page load to less than 30 secs, pretty conclusive proof that there is a significant overhead when calling partial views. I'm sure this is negligible when you have a single call, however in a loop it all adds up so I'd recommended avoiding partial views in a loop if possible.