根据这个article我正在尝试绑定(bind)一个非顺序项目列表。
查看:
<%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" />
<%} %>
操作方法:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Products(IList<Product> products)
{
return View("Index");
}
绑定(bind)似乎对我不起作用,参数 products 始终包含 null。我错过了什么吗?
非常感谢任何帮助,谢谢。
请注意,我使用的是 ASP.NET MVC 1.0
最佳答案
从 ASP.NET MVC 2.0 开始,默认模型绑定(bind)器能够绑定(bind)具有非顺序索引的集合。这在 ASP.NET MVC 1.0 中不受支持。
关于c# - 非顺序列表绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7807127/