I'm using CheckboxFor when building a form which has a list of checkboxes:
<div id="TestSections">
@foreach (var item in Model)
{
<div class="form-group">
<label class="col-md-2 control-label">
@if (item.IsRequried)
{
<text>Required - </text>
}
@item.Name
</label>
<div class="md-checkbox-list col-md-10">
<div>
@Html.CheckBoxFor(i => item.IsChecked)
</div>
</div>
</div>
}
</div>
The Model being passed is:
public class TestModel
{
public int TestId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public bool IsRequired { get; set; }
// used for checkbox
public bool IsChecked { get; set; }
}
The view builds out the checkboxes correct, but i'm not able to get them when the form posts back:
[HttpPost]
public ActionResult TestSection(int id, List<TestModel> model)
{
return View();
}
the model is always null.