I have a view model class that looks something like this
public class ViewModel
{
public string Name { get; set; }
public IList<SubViewModel> Subs { get; set; }
}
public class SubViewModel
{
public string Name { get; set; }
public bool IsSet { get; set; }
public int Id { get; set; }
}
In my HTML I then have
<%= Html.TextBoxFor(x=>x.Name) %>
<% foreach(var sub in x.Subs) { %>
<%= sub.Name %>
<%= Html.Checkbox("Subs["+index of current sub+"].IsSet",sub.IsSet) %>
<% } %>
In my controller code for a submit of a form surrounding these I do the following
public Save()
{
var oldModel = GetOldModelFromSession();
TryUpdateModel(oldModel);
SaveModelToDb(oldModel);
}
Now when I call try update model it replaces the "Subs" list with a new one rather than just updating the IsSet property at the correct index. Is this possible to have working (I can assume that the oldModel I get is the same as the one originally sent to the page.)