亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

MVC3非順序索引和DefaultModelBinder

MVC3非順序索引和DefaultModelBinder

MMTTMM 2019-11-27 14:38:22
MVC 3.0中的默認模型綁定器是否能夠處理非順序索引(對于簡單模型類型和復雜模型類型),是否正確?我遇到過建議使用它的帖子,但是在我的測試中似乎沒有。給定回發值:items[0].Id = 10items[0].Name = "Some Item"items[1].Id = 3items[1].Name = "Some Item"items[4].Id = 6items[4].Name = "Some Item"和控制器方法:public ActionResult(IList<MyItem> items) { ... }唯一加載的值是項目0和1。只需忽略第4項。我已經看到了許多用于生成自定義索引(將模型綁定到列表)的解決方案,但是它們似乎都是針對MVC的早期版本的,大多數都是有點“笨拙”的IMO。我想念什么嗎?
查看完整描述

3 回答

?
莫回無

TA貢獻1865條經驗 獲得超7個贊


我正在工作,您必須記住要添加一個常見的索引隱藏輸入,如您所引用的文章中所述:


隱藏的輸入name = Items.Index是關鍵部分


<input type="hidden" name="Items.Index" value="0" />

<input type="text" name="Items[0].Name" value="someValue1" />


<input type="hidden" name="Items.Index" value="1" />

<input type="text" name="Items[1].Name" value="someValue2" />


<input type="hidden" name="Items.Index" value="3" />

<input type="text" name="Items[3].Name" value="someValue3" />


<input type="hidden" name="Items.Index" value="4" />

<input type="text" name="Items[4].Name" value="someValue4" />

希望這可以幫助



查看完整回答
反對 回復 2019-11-27
  • 3 回答
  • 0 關注
  • 518 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號