I want a text box, bound to an array, to post the form when its changed.
I was following this post to get it to work but the property on my model is always null. Why?
Model
public class TestModel
{
public int[] MyInts;
}
Controller
public ActionResult Index(TestModel model)
{
if (model.MyInts == null) // <-- Always true
{
model.MyInts = new int[] { 1, 2, 3, 4 };
}
}
View
@model TestModel
@using (Html.BeginForm("Index", "Test", FormMethod.Post, new { id = "TestForm" }))
{
<table class="table">
<thead>
<tr>
<th />
@for (int i = 0; i < Model.MyInts.Count(); i ++)
{
<th>
@Html.TextBoxFor(x => Model.MyInts[i], new { onchange = "this.form.submit();" })
</th>
}