Search This Blog

Wednesday, September 28, 2016

Html.Partial() Vs Html.RenderPartial()


Html.Partial() Vs Html.RenderPartial():-

Both of these helper methods used for rendering partial views.The following are the diffrences.

1.The return type of "RenderPartial" is void, where as "Partial" returns"MvcHtmlString".
2. Syntax for invoking Partial() and RenderPartial() methods in Razor views
@Html.Partial("NameOfPartialView")
{ Html.RenderPartial("NameOfPartialView");  }

When would you use Partial() or RenderPartial() ?
The main difference is that "RenderPartial()" returns void and the output will be written directly to the output stream, where as the "Partial()" method returns MvcHtmlString, which can be assigned to a variable and manipulate it if required. So, when there is a need to assign the output to a variable for manipulating it, then use Partial(), else use RenderPartial().

Which performance is better? 
From a performance perspective, rendering directly to the output stream is better RenderPartial() does exactly the same thing and is better for performance over Partial().

No comments:

Post a Comment