Skip to main content
added 652 characters in body
Source Link
Jesse van Assen
  • 2.3k
  • 2
  • 16
  • 19

It's because you gave the checkbox the name @item.Name. The model binder will check if it can map it to a particular property in the model, but it can't find it because it is looking for the value of @item.Name and not for the SpecialtyList property.

Phil Haack has a nice article about model binding to a list. I suggest you check that one out.

Also, I don't think you can model bind to a custom object, because the values of the checkboxes that are coming in is are just strings. You should make another property on your model that is of type IEnumerable to which the values of the checkboxes are model binded. It would look like this:

public IList<ViewModelCheckBox> SpecialityList { get; set; }
public IEnumerable<string> SpecialityListValues { get; set; }

This way you can use the SpecialityList to fill the values in the view, and the SpecialityListValues to retrieve the values. Note that the name of the checkboxes has to correspond with SpecialityListValues.

It's because you gave the checkbox the name @item.Name. The model binder will check if it can map it to a particular property in the model, but it can't find it because it is looking for the value of @item.Name and not for the SpecialtyList property.

Phil Haack has a nice article about model binding to a list. I suggest you check that one out.

It's because you gave the checkbox the name @item.Name. The model binder will check if it can map it to a particular property in the model, but it can't find it because it is looking for the value of @item.Name and not for the SpecialtyList property.

Phil Haack has a nice article about model binding to a list. I suggest you check that one out.

Also, I don't think you can model bind to a custom object, because the values of the checkboxes that are coming in is are just strings. You should make another property on your model that is of type IEnumerable to which the values of the checkboxes are model binded. It would look like this:

public IList<ViewModelCheckBox> SpecialityList { get; set; }
public IEnumerable<string> SpecialityListValues { get; set; }

This way you can use the SpecialityList to fill the values in the view, and the SpecialityListValues to retrieve the values. Note that the name of the checkboxes has to correspond with SpecialityListValues.

Source Link
Jesse van Assen
  • 2.3k
  • 2
  • 16
  • 19

It's because you gave the checkbox the name @item.Name. The model binder will check if it can map it to a particular property in the model, but it can't find it because it is looking for the value of @item.Name and not for the SpecialtyList property.

Phil Haack has a nice article about model binding to a list. I suggest you check that one out.