Is there a performance difference between using an HtmlHelper or a Partial for a given task?
For example, I'm writing an HtmlHelper "control" to create a link in an editor with the following signature:
public static HtmlString RecordNameLink(
this HtmlHelper htmlHelper,
string linkText,
string editActionName,
object editRouteValues,
string deleteActionName = null,
object deleteRouteValues = null)
In this case the edit button will always be displayed, and the delete button will only be displayed if it is included. Alternately, I could do this:
@Html.Partial("Controls/RecordNameLink", Model)
(Or pass a partial-specific model)
But is there a reason to choose one over the other, specifically does one have better performance than the other? (though I'm open to learning more about the differences in general)
Thanks.
In MVC 3, for this sort of thing its going to be faster for you to render with an html helper than a Partial.
Do a test where you render a partial 100+ times in a loop, vs have the partial contain the loop (partial render per row of a table, vs partial render of all rows of a table). You might be quite surprised at the result.
Your HTML Helper will skip the viewengine having to hunt for the partial, the call to the Virtual Path Provider to load it, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With