Lam*_*mps 3 .net c# asp.net-mvc model-binding
根据这篇文章,我试图绑定一个非顺序项列表.
视图:
<%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" />
<%} %>
Run Code Online (Sandbox Code Playgroud)
行动方式:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Products(IList<Product> products)
{
return View("Index");
}
Run Code Online (Sandbox Code Playgroud)
绑定似乎对我不起作用,参数产品总是包含null.我错过了什么吗?
任何帮助非常感谢,谢谢.
请注意,我使用的是ASP.NET MVC 1.0