문제

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?

도움이 되었습니까?

해결책

This might work

CheckboxList in MVC3.0

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top