Difference between Html.Partial and Html.RenderPartial

Thursday, 6 February 2014




Html.Partial vs Html.RenderPartial in ASP.NET MVC

Both functions used for rendering the partial view and use same logic to render the partial view, but their fundamental difference is in their return type.
@Html.RenderPartial returns void and that’s why its require following syntax. Html.RenderPartial output their content into the same TextWriter object as used in the current template. This is more efficient, because the view content is not buffered in memory.

@{
Html.RenderPartial("TestPartialView1");
}

Where Html.Partial return MvcHtmlString which you can keep in any variable for latter use. That’s why it require following syntax.

@Html.Partial("TestPartialView1")