I'm having trouble binding a basic list of values to the model in my post action in the controller. The list is returning null.
I have a viewmodel which looks like this:
public class DistributionListFormModel : FormViewModel
{
[Required(ErrorMessage = "The title is required")]
public string Title { get; set; }
public List<DistributionItem> DistributionItems { get; set; }
}
public class DistributionItem
{
public string LabelText { get; set; }
public bool Signup { get; set; }
}
Ok - so in my controller, I populate the DistributionItems list with some dud values within the index method. And here is a snapshot of my view:
<div class="o-wrapper">
@using (Html.BeginForm("Submit", "MyController", FormMethod.Post))
{
foreach (var item in Model.DistributionItems)
{
<p>@item.LabelText</p>
@Html.CheckBoxFor(m => item.Signup)
}
<button type="submit">SUBMIT</button>
}
Any idea why the DistributionItems list is null in the post controller? I found some articles but they all relate to very older versions of ASP.Net...
Thanks!!