Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between Html.Action and Html.RenderAction

I've been trying to figure out the difference between RenderAction and Action. I don't know if I'm so concerned about the differences at this point, as to why I can't get RenderAction to work. From what I can tell, I'm passing in the correct parameters. The overload I'm using seems to be the same for both:

@Html.RenderAction(Action, Controller, Route)  @Html.Action("Breadcrumb", "Navigation", new {SeoUrl = Model.CarlineBucket.SEOURLName})  @Html.RenderAction("Breadcrumb", "Navigation", new {SeoUrl = Model.CarlineBucket.SEOURLName}) 

I get a compilation error when I try and use RenderAction:

CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments.

Any tips or hints? Should I not even be bothering with RenderAction?

like image 530
MrGrigg Avatar asked Apr 27 '11 21:04

MrGrigg


People also ask

What is the difference between HTML partial vs HTML RenderPartial and HTML action vs HTML RenderAction?

Partial injects the html string of the partial view into the main view. Html. RenderPartial writes html in the response stream. Here is what I have found:Use RenderAction when you do not have a model to send to the view and have a lot of html to bring back that doesn't need to be stored in a variable.

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 is HTML action?

The action attribute specifies where to send the form-data when a form is submitted.

What is RenderAction in MVC?

RenderAction(HtmlHelper, String) Invokes the specified child action method and renders the result inline in the parent view. RenderAction(HtmlHelper, String, Object) Invokes the specified child action method using the specified parameters and renders the result inline in the parent view.


2 Answers

Try:

@{Html.RenderAction("Breadcrumb", "Navigation", new {SeoUrl = Model.CarlineBucket.SEOURLName});} 

@Html.RenderAction() generates a write call to output something on the page and in your case you are not doing so because RenderAction renders the result directly to the Response.

Instead of

@Html.RenderAction() 

Use

@{Html.RenderAction();} 
like image 72
CD.. Avatar answered Oct 08 '22 03:10

CD..


From Phil Haack:

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.

like image 23
ataddeini Avatar answered Oct 08 '22 02:10

ataddeini