I have a view that looks like this:
@model List<int>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@using (Html.BeginForm())
{
<ul>
@{int counter = 0;}
@foreach (var i in Model)
{
<li>@Html.TextBoxFor(m => m[counter])</li>
counter++;
}
</ul>
}
my problem is that the generated html looks like this…
<li><input name="[0]" type="text" value="1" /></li>
etc.. etc...
When I post back to the controller, the form names don’t bind to a my controller. Any thoughts on how to fix it (prefix or something perhaps?)
I had the same problem some time ago, and this is my solution (workaround?)
You can use this code in your view to generate the form:
And in your controller define action with
List<int> numberparameterI have never tried to find out why the simple solution doesn’t work, but I guess, that model binder needs some property name to work with.