In ASP.NET MVC, what is the difference between:
Html.Partial
and Html.RenderPartial
Html.Action
and Html.RenderAction
RenderPartial(HtmlHelper, String) Renders the specified partial view by using the specified HTML helper. RenderPartial(HtmlHelper, String, Object) Renders the specified partial view, passing it a copy of the current ViewDataDictionary object, but with the Model property set to the specified model.
RenderPartial is used to display a reusable part of within the same controller and RenderAction render an action from any controller. They both render the Html and doesn't provide a String for output.
B) @Html. RenderPartial Returns nothing (void), it is faster than @Html. Partial, moreover requires not to create action.
@Html.Partial This method renders the view as an HTML-encoded string. We can store the method result in a string variable. The Html. RenderPartial method writes output directly to the HTTP response stream so it is slightly faster than the Html.
Html.Partial
returns a String. Html.RenderPartial
calls Write
internally and returns void
.
The basic usage is:
// Razor syntax @Html.Partial("ViewName") @{ Html.RenderPartial("ViewName"); } // WebView syntax <%: Html.Partial("ViewName") %> <% Html.RenderPartial("ViewName"); %>
In the snippet above, both calls will yield the same result.
While one can store the output of Html.Partial
in a variable or return it from a method, one cannot do this with Html.RenderPartial
.
The result will be written to the Response
stream during execution/evaluation.
This also applies to Html.Action
and Html.RenderAction
.
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