How do I achieve ModelBinding with Html.RenderAction?
-
27-10-2019 - |
Question
I'm working through a MVC book which uses the older version of Html.RenderAction
. So it looks like this in the book Html.RenderAction("Summary", "Cart");
I have had to convert to Html.RenderAction<CartController>(m => m.Summary(new Cart()));
.
Where Summary looks like:
public ViewResult Summary(Cart cart)
{
return View(cart);
}
I have a binding set up for Cart in the global.asax
ModelBinders.Binders.Add(typeof(Cart), new CartModelBinder());
So what is the best way do get the Binding to create the parameter cart
instance rather then me manually doing it?
I have several ideas of how to fix this, but since I'm new to MVC I'm looking to see what the accepted practice is.
Thanks
Solution
Instead of using
HTML.RenderAction()
use
HTML.RenderPartial()
for eg:-
<% Html.RenderPartial("Summary", new cart(parameters)); %>
this will work sure.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow