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
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.
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.
Action() is actually calling the action, computing the DateTime, and rendering the view, whereas Html. Partial() is only rendering the view.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With