I’ve got my Partial view :
@foreach (var checkbox in Model.TimeLimit)
{
<div class="editor-label">
@Html.Label(checkbox.Name)
@Html.Hidden(checkbox.Id)
@Html.CheckBoxFor(c=>checkbox.IsChecked)
</div>
}
I’ve got a ParentViewModel which contains :
public IEnumerable<URLTimeLimitViewModel> TimeLimit { get; set; }
and URlTimelimitViewmodel contains :
public string Name { get; set; }
public int Id { get; set; }
public bool IsChecked { get; set; }
When I call submit button, Timelimit in ParentViewModel returns null, why?
You need to change your loop – the model binder cannot figure out what to bind the posted values to:
You’ll also need to declare your
TimeLimitproperty as something other than an IEnumerable, I’d recommend a generic List (LINQs ToList method is very convenient!):