非顺序列表约束力不工作 [英] Non sequential list binding not working
本文介绍了非顺序列表约束力不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据此文章我想绑定的非连续项的列表。
As per this article I am trying to bind a list of non sequential items.
查看:
<%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");
}
绑定似乎并不为我工作,该参数的产品总是包含空值。我失去了一些东西?
Binding doesn't seems to work for me, the parameter products always contains null. Am I missing something?
任何帮助非常AP preciated,谢谢。
Any help much appreciated, Thanks.
请注意,我使用的ASP.NET MVC 1.0
Please note, I am using ASP.NET MVC 1.0
推荐答案
默认的模型粘合剂能够结合馆藏与ASP.NET MVC 2.0起非连续索引。这不是在ASP.NET MVC 1.0的支持。
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.
这篇关于非顺序列表约束力不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文