Friday, August 8, 2014

Difference/Similarities BETWEEN HTML.RENDERACTION AND HTML.ACTION

 

image

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 action method in view.

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

The way to call action via RenderAction is shown below:

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

 

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

image

 

@{ 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 action via RenderAction is shown below:

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

It returns Voids and render/give result directly to the response .

 

image 


Both methodsis also used for rendering the partial view using 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 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 readingSmile

0 comments :

Post a Comment