Non sequential list binding not working

折月煮酒 提交于 2019-12-03 21:45:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!