Non sequential list binding not working

2019-02-15 07:53发布

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条回答
男人必须洒脱
2楼-- · 2019-02-15 08:35

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.

查看更多
登录 后发表回答