I would like to know difference between
in asp.net MVC, when we should use which HTML helper method?
Thanks
So here is the difference between HTML.Partial and HTML.RenderPatial
It Renders the partial view as an HTML-encoded string.
This method result can be stored in a variable since it returns MvcHtmlString value(which can be assigned to a variable and manipulate it if required).
You don't need to create any action, you can directly call the partial view, and render it's results, with model or without passing any model.
@Html.Partial("_PartialViewName")?
This method results will be directly written to the HTTP response stream means it uses the same TextWriter object as used in the current web page/template.
This method also returns void.
Use RenderPartial when you have a model to send to the view and there will be a lot of HTML that doesn't need to be stored in a variable.
@{Html.RenderPartial("_ViewName");}?
@Html.Action("Action","Controller")
@{ Html.RenderAction ("Action","Controller"); }?
@Html.Partial("PartialViewName", new { id = 1} );
@{ Html.RenderPartial("PartialViewName", ModelObject);}
Both are action helper methods in ASP.NET MVC. Generally both methods are used for calling action methods or child action methods and rendering the result of the action method in the view.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly