【发布时间】:2011-10-18 12:22:37
【问题描述】:
根据article,我正在尝试绑定非连续项目的列表。
查看:
<%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");
}
绑定似乎对我不起作用,参数 products 总是包含 null。我错过了什么吗?
非常感谢任何帮助,谢谢。
请注意,我使用的是 ASP.NET MVC 1.0
【问题讨论】:
-
您在这里拼错了产品:
<%using (Html.BeginForm("Producs", "Home", FormMethod.Post))。您只是在这里输入了错误的代码,还是您的实际代码也是这样?编辑:没关系。看看达林发布了什么。 -
感谢您发现这一点。这是一个错字,我现在就编辑它。
标签: c# .net asp.net-mvc model-binding