My controller action is here:
[HttpPost]
public ActionResult Index(List<Widget> widgets, int index)
{
widgets.RemoveAt(index);
return View(widgets);
}
My post to this action looks like this:
[0].Name a
[1].Name b
[2].Name c
index 1
When I debug, I see that there is only one item in my list. I can correct the issue by changing the parameter name from index to _index.
I couldn’t find anything where index was a reserved word. Any thoughts as to why this happens?
Mvc model binding can work with lists by binding consecutive indexes to items in the collection as in your example.
However you can get mvc to bind using any given key, it does this by using a form field with equal specificity named
index.E.g.
Phil haack gives a good tutorial on this
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
Mvc maybe getting confused at this point and trying to invoke this type of binding