How to achieve ModelBinding using Html.RenderAction?

I work through an MVC book that uses an older version Html.RenderAction. So it looks like this in a book Html.RenderAction("Summary", "Cart");I had to convert to Html.RenderAction<CartController>(m => m.Summary(new Cart()));.

The summary looks like this:

public ViewResult Summary(Cart cart)
{
    return View(cart);
}

I have a basket binding in global.asax

ModelBinders.Binders.Add(typeof(Cart), new CartModelBinder());

So, what is the best way to get the binding to instantiate the parameter cart, and not to do it manually?

I have a few ideas on how to fix this, but since I'm new to MVC, I want to see what the accepted practice is.

thank

+3
source share
1 answer

Instead of using

HTML.RenderAction()

using

HTML.RenderPartial()

eg: -

<% Html.RenderPartial("Summary", new cart(parameters)); %>

it will work.

0
source

All Articles