Friday 31 August 2018

ASP.NET MVC: Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

These are the common yet confusing Html helpers provided by ASP.NET MVC Razor Views.

Html.Partial() and Html.Action() returns MvcHtmlString. This means, it writes your output in parent view first and then return complete result to client's browser.
  • These methods are less resource intensive.
  • Slower than 'render' methods.
  • Should be preferred if your website has heavy traffic.

Html.RenderPartial() and Html.RenderAction() have void return type. This means, they write nothing on its parent view. So how do we still see the output? The answer is- these methods write output directly to the response.
  • Consume resources more.
  • It is faster method because it is rendered separately.
  • Should be preferred if your website has inadequate traffic.

Html.Partial() and Html.RenderPartial() can be used without an action method. If your parent view already has a model, you can pass that model to sub view you are trying to render.


Html.Action() and Html.RenderAction() can only be used with an action or child action. Use it when child view will have independent model.

More comments are welcome! :) 

No comments:

Post a Comment