我無法獲取DropDownListFor以綁定到我的模型。 DisplayOrder返回null,VarietyFamilyID始終爲0.我有一個未知數量的對象進行編輯,所以我試圖使用EditorTemplate。DropDownListFor未綁定在EditorTemplate中
EditorTemplate視圖
@model Wysocki_Variety_Management.Models.Image
<div>
@Html.HiddenFor(i=>i.ImageStreamID)
@Model.helperString
@Html.DropDownListFor(i=>i.DisplayOrder, new SelectList(ViewBag.DisplayOptions, "Key", "Value"))
@Html.DropDownListFor(i => i.VarietyFamilyID, new SelectList(ViewBag.Variety, "VarietyFamilyID", "Name"))
@Ajax.ActionLink("Try Me",
"UpdateImage",
"Images",
new { s = Model.ImageStreamID, dislplayOrder = Model.DisplayOrder, familyID = Model.VarietyFamilyID },
new AjaxOptions {})
</div>
查看渲染模板
@model List<Wysocki_Variety_Management.Models.Image>
@using (Html.BeginForm("UpdateImage", "Images"))
{
<div>
@Html.EditorForModel()
</div>
}
控制器動作簽名
public ActionResult UpdateImage(Guid s, int displayOrder,int familyID)
編輯
不能確定下來表決Ø r評論。當我使用EditorTemplate和@ Html.EditorForModel時,我爲模型的每個成員獲得多個輸入。
<form action="/Images/UpdateImage" method="post"> <div>
<div>
<input data-val="true" data-val-required="The Guid field is required." name="[0].ImageStreamID" type="hidden" value="e48aab34-0fe6-e511-8ebf-005056c00008" />
<select data-val="true" data-val-number="The field Int32 must be a number." data-val-required="The Int32 field is required." name="[0].DisplayOrder"><option value="312">Tuber</option>
<option value="313">Plant</option>
<option value="314">Marketing</option>
</select>
<select data-val="true" data-val-number="The field Int32 must be a number." data-val-required="The Int32 field is required." name="[0].VarietyFamilyID"><option value="0">Fianna</option>
<option value="0">Linzer Delikatesse</option>
<option value="3">Markies</option>
<option value="0">Provento</option>
<option value="5">Roko</option>
<option value="6">75-11-15 Sprint</option>
<option value="7">Alegria</option>
</select>
<a data-ajax="true" href="/Images/UpdateImage?s=e48aab34-0fe6-e511-8ebf-005056c00008&dislplayOrder=0&familyID=0">Try Me</a>
</div><div>
<input data-val="true" data-val-required="The Guid field is required." name="[1].ImageStreamID" type="hidden" value="e58aab34-0fe6-e511-8ebf-005056c00008" />
<select data-val="true" data-val-number="The field Int32 must be a number." data-val-required="The Int32 field is required." name="[1].DisplayOrder"><option value="312">Tuber</option>
<option value="313">Plant</option>
<option value="314">Marketing</option>
</select>
<select data-val="true" data-val-number="The field Int32 must be a number." data-val-required="The Int32 field is required." name="[1].VarietyFamilyID"><option value="0">Fianna</option>
<option value="0">Linzer Delikatesse</option>
<option value="3">Markies</option>
<option value="0">Provento</option>
<option value="5">Roko</option>
<option value="6">75-11-15 Sprint</option>
<option value="7">Alegria</option>
</select>
<a data-ajax="true" href="/Images/UpdateImage?s=e58aab34-0fe6-e511-8ebf-005056c00008&dislplayOrder=0&familyID=0">Try Me</a>
</div><div>
<input data-val="true" data-val-required="The Guid field is required." name="[2].ImageStreamID" type="hidden" value="e68aab34-0fe6-e511-8ebf-005056c00008" />
<select data-val="true" data-val-number="The field Int32 must be a number." data-val-required="The Int32 field is required." name="[2].DisplayOrder"><option value="312">Tuber</option>
<option value="313">Plant</option>
<option value="314">Marketing</option>
</select>
<select data-val="true" data-val-number="The field Int32 must be a number." data-val-required="The Int32 field is required." name="[2].VarietyFamilyID"><option value="0">Fianna</option>
<option value="0">Linzer Delikatesse</option>
<option value="3">Markies</option>
<option value="0">Provento</option>
<option value="5">Roko</option>
<option value="6">75-11-15 Sprint</option>
<option value="7">Alegria</option><option value="331">A02507-2LB</option>
</select>
<a data-ajax="true" href="/Images/UpdateImage?s=e68aab34-0fe6-e511-8ebf-005056c00008&dislplayOrder=0&familyID=0">Try Me</a>
</div><div>
<input data-val="true" data-val-required="The Guid field is required." name="[3].ImageStreamID" type="hidden" value="e78aab34-0fe6-e511-8ebf-005056c00008" />
<select data-val="true" data-val-number="The field Int32 must be a number." data-val-required="The Int32 field is required." name="[3].DisplayOrder"><option value="312">Tuber</option>
<option value="313">Plant</option>
<option value="314">Marketing</option>
</select>
<select data-val="true" data-val-number="The field Int32 must be a number." data-val-required="The Int32 field is required." name="[3].VarietyFamilyID"><option value="0">Fianna</option>
<option value="0">Linzer Delikatesse</option>
<option value="3">Markies</option>
<option value="0">Provento</option>
<option value="5">Roko</option>
<option value="6">75-11-15 Sprint</option>
<option value="7">Alegria</option>
你是什麼意思_I有未知數量的對象edit_?您顯示的視圖只呈現一個對象,除非模型爲「IEnumerable」,在這種情況下,POST方法中的模型也必須爲'IEnumerable ' –