Difference between Html.Partial and Html.RenderPartial and Html.Action and Html.RenderAction

Html.Partial returns MVCHtmlString which can be assigned to a variable and manipulate if required.

Syntax : @Html.Partial("ViewName")

Html.RenderPartial returns void and output will be written directly to the output stream.

Syntax : @{ Html.RenderPartial("ViewName"); }

Note: We can also pass the model to the Partial

Syntax : @Html.Partial("ViewName", Model)
               @{ Html.RenderPartial("ViewName", Model) }


Html.Action Invokes the specified child action method and returns the result as an HTML string

Syntax : @{string result = @Html.Action("Action", "Controller", new { param = "value"} ).ToString();}

Html.RenderAction Invokes the specified child action method and renders the result inline in the parent view.

Syntax : @{Html.Action("Action", "Controller", new { param = "value"} ).ToString();}

Note: This method is faster than the Action method since its result is directly written to the HTTP response stream. 

Comments

Popular posts from this blog

SQL Interview Questions and Answers

Generic Interface and Factory Pattern in C#

How to get device info IMEI programmatically in xamarin android