The @Matheusbessa response works for a checkbox. For a list, you need to use the mapping structure for an array. See what changes:
The view:
@using (Html.BeginForm("Index", "Home"))
{
<input type="checkbox" name="CheckboxList[0]" />
<input type="checkbox" name="CheckboxList[1]" />
<input type="checkbox" name="CheckboxList[2]" />
...
<input type="checkbox" name="CheckboxList[n]" />
<input type="submit" value="Submit"/>
}
And the controller:
[HttpPost]
public ActionResult Index(String[] CheckboxList)
{
...
}
It is natural that your viewmodel has more information. If necessary, this array would be a viewmodel Property.
It is important to note that indexes need to be sequential and start at 0. If this is not respected, the Binder model will not accept as an enumerator.
As @Matheusbessa commented, a checkbox marked will give the string on. Anything other than this represents the clean checkbox.
Eduardo, there is another library called ASP.net Awesome, which is excellent too. Here the direct link to the Checkboxlist component. I hope it helped you ! Here’s another direct link to how to use the component
– Érik Thiago
Even ball show Erik, many cool components in this library! Thanks for the tip!
– Eduardo Bottcher
Dude, she’s really massive. I used the lookup and wow, it’s really top !
– Érik Thiago