I have a class like this:
public class SomeModel
{
public List<Item> Items { get; set; }
public SomeModel()
{
this.Items = new List<Item>();
}
}
Where there can be a variable amount of Items upon form post, zero to many. I'm using javascript to dynamically append hidden input fields on submit:
$("#container").children(".item").each(function (i) {
form.append('<input type="hidden" name="Items[' + i + '].Id" value="' + $(this).val() + '" />');
});
However, after submitting, I get this error:
System.NotSupportedException: Collection is read-only.
The rendered syntax is basically the same as one I would get using @Html.HiddenFor(model => model.Items[i].Id) with model.Items being an array instead of a list, and that works fine. What is going wrong here?
Action Method signature:
public ActionResult Post(SomeModel m)
{