HtmlHelper vs Partial Performance

Is there a performance difference between using HtmlHelper or Partial for a given task?

For example, I write HtmlHelper "control" to create a link in the 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 enabled. Alternatively, I could do this:

 @Html.Partial("Controls/RecordNameLink", Model) 

(Or pass a partial model)

But is there a reason for choosing one over the other, in particular, is performance better than the other? (although I am open to learn more about the differences in general)

Thanks.

+4
source share
1 answer

In MVC 3, for this kind of thing, it will be faster for you with the html helper than Partial.

Carry out a test in which you execute a partial 100+ times in a loop, vs partially contain a loop (partial rendering in a row of a table, as well as partial rendering of all rows of a table). You may be very surprised at the result.

Your HTML helper will miss a view that requires a partial search, a call to the virtual path provider to load it, etc.

+3
source

All Articles