Model Binding an IList of selected items only

Posted by jeef3 on Stack Overflow See other posts from Stack Overflow or by jeef3
Published on 2009-10-02T01:19:17Z Indexed on 2010/03/31 11:03 UTC
Read the original article Hit count: 356

Filed under:
|

I have an action method setup:

public ActionResult Delete(IList<Product> products)

And a table of products in my view. I have got Model Binding working so that on submit I can populate the products list. But I would like to populate it with only the products that are selected via a checkbox.

I think I could do it by changing the action method to this:

public ActionResult Delete(IList<Product> products, IList<int> toDelete)

And passing the list of check boxes to the toDelete but I would really like to avoid changing the method signature if possible.

Is there a way to pass only the selected items? Or am I going to have to write a custom ModelBinder?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about model-binding