Question

I have a view with a form that's is typed to a viewmodel called AddEditItemVM. This viewmodel has the following property:

public List<Category> Categories{get;set;}

What im trying is two things:

  • Render a checkbox foreach Category in the generic category list of my viewmodel.

  • Make that when the form is posted receive, in my controller action, the property Categories instantiated (into the instance of AddEditItemVM)

About the first point, i would like to use any helper (if exists) that renders a group of checkboxes using lambda expressions like (m=>m.Categories), instead to render the checkbox with a foreach into the view.

About the second point, i read that there is one feature in MVC called Custom Model Binders. These get values from ValueProviders (querystring, cookies, or Form values) and creates the necessary instances passing it to specific action called after a form was posted. Should i create one custom model binder in order to receive my property Categories instantiated?

Was it helpful?

Solution

This might work

CheckboxList in MVC3.0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top