Kev*_*vin 5 asp.net-mvc list model-binding indices
我正在关注来自Phil Haack的http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx上的信息
他谈到了非顺序指数:
<form method="post" action="/Home/Create">
<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" />
</form>
Run Code Online (Sandbox Code Playgroud)
当您使用与TextBoxFor的模型绑定时,这在MVC3中是否可行?
这是使用sequentiel索引执行此操作的方法:
@Html.TextBoxFor(m => m[i].Value)
Run Code Online (Sandbox Code Playgroud)
如果不可能的话,如果我的指数不是连续的,我还能做些什么吗?
AFAI 了解非顺序索引技术需要为每个索引值添加隐藏字段。我非常确定 Html.TextBoxFor 助手本身不会生成任何其他隐藏字段。也许您可以通过手动添加具有非顺序索引的隐藏字段来实现此目的。