Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

In ASP.NET MVC, what is the difference between:

  • Html.Partial and Html.RenderPartial
  • Html.Action and Html.RenderAction
like image 613
Ghooti Farangi Avatar asked Mar 09 '11 15:03

Ghooti Farangi


People also ask

What is HTML RenderPartial?

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.

What is the difference between RenderPartial and RenderAction?

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.

What are the benefits of HTML RenderPartial?

B) @Html. RenderPartial Returns nothing (void), it is faster than @Html. Partial, moreover requires not to create action.

Why we use HTML partial in MVC?

@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.


1 Answers

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.

like image 160
GvS Avatar answered Oct 05 '22 02:10

GvS