Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RenderAction differences

Why is this code correct:

 @{
   Html.RenderAction("PostImagesForPost", "BlogPost", new { id = Model.ID });
  }

And this code

 @Html.RenderAction("PostImagesForPost", "BlogPost", new { id = Model.ID })

through this error message:

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

Why it is so important to use the '{' '}'?

Thanks

like image 527
POIR Avatar asked Mar 19 '14 14:03

POIR


People also ask

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 difference between partial and RenderPartial?

The primary difference between the two methods is that Partial generates the HTML from the View and returns it to the View to be incorporated into the page. RenderPartial, on the other hand, doesn't return anything and, instead, adds its HTML directly to the Response object's output.

What is difference between partial and action?

Action() is actually calling the action, computing the DateTime, and rendering the view, whereas Html. Partial() is only rendering the view.

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

Render vs Action partial RenderPartial will render the view on the same controller. But RenderAction will execute the action method , then builds a model and returns a view result.


1 Answers

Html.RenderAction has to be called within a script block and can't be called in mark-up.

As an alternative in markup you would use:

@Html.Action("PostImagesForPost", "BlogPost", new { id = Model.ID })

For the differences on Action and RenderAction see here:

http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx/

like image 73
hutchonoid Avatar answered Sep 23 '22 14:09

hutchonoid