问题
As per this article I am trying to bind a list of non sequential items.
View:
<%using (Html.BeginForm("Products", "Home", FormMethod.Post))
{ %>
<input type="hidden" name="products.Index" value="cold" />
<input type="text" name="products[cold].Name" value="Beer" />
<input type="text" name="products[cold].Price" value="7.32" />
<input type="hidden" name="products.Index" value="123" />
<input type="text" name="products[123].Name" value="Chips" />
<input type="text" name="products[123].Price" value="2.23" />
<input type="hidden" name="products.Index" value="caliente" />
<input type="text" name="products[caliente].Name" value="Salsa" />
<input type="text" name="products[caliente].Price" value="1.23" />
<input type="submit" value="Submit" />
<%} %>
Action method:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Products(IList<Product> products)
{
return View("Index");
}
Binding doesn't seems to work for me, the parameter products always contains null. Am I missing something?
Any help much appreciated, Thanks.
Please note, I am using ASP.NET MVC 1.0
回答1:
The default model binder is capable of binding collections with non-sequential indexes starting from ASP.NET MVC 2.0. This is not supported in ASP.NET MVC 1.0.
来源:https://stackoverflow.com/questions/7807127/non-sequential-list-binding-not-working