加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 模型绑定到MVC 3中可能存在非顺序索引的列表?

发布时间:2020-12-16 07:44:19 所属栏目:asp.Net 来源:网络整理
导读:我正在关注来自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
我正在关注来自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>

当您使用与TextBoxFor的模型绑定时,这在MVC3中是否可行?
这是使用sequentiel索引执行此操作的方法:

@Html.TextBoxFor(m => m[i].Value)

如果不可能的话,如果我的指数不是连续的,我还能做些什么吗?

解决方法

AFAI理解非顺序索引技术需要为每个索引值添加隐藏字段.我很确定Html.TextBoxFor帮助器本身不会生成任何额外的隐藏字段.您可以通过手动添加带有非顺序索引的隐藏字段来实现此目的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读