Differences and Similiarities Of Html.RenderAction and Html.Action Method

In this article we'll see the differences and similiarities of the Html.RenderAction and Html.Action methods.

Html.RenderAction() and Html.Action() 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.

Difference Between Action & RenderAction Method

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

The way to call an action via RenderAction is shown below:

  1. @Html.Action("ChildAction", "Home", new { param = "first" })

This method result can be stored in a variable, since it returns a string type value. Kindly look at the image shown below:

Action Method in MVC

@{ Html.RenderAction(): Invokes the specified child action method and renders the result inline in the parent view.

This method is more efficient if the action returns a large amount of HTML.

The way to call an action via RenderAction is shown below:

  1. @{Html.RenderAction("ChildAction", "Home",new { param = "first" });}

It returns Voids and renders/gives a result directly to the response.

RenderAction Method in MVC

Both methods are also used for rendering the partial view using the Child Action.

The difference between the two is that Html.RenderAction will render the result directly to the Response (which is more efficient if the action returns a large amount of HTML) whereas Html.Action returns a string with the result.

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

Thanks. To learn more about MVC please go through the following link.

MVC Articles
 
Enjoy coding and reading.

Up Next
    Ebook Download
    View all
    Learn
    View all