為什么DropDownListFor在提交后失去了多個(gè)選擇,而ListBoxFor卻沒有?我讀過許多關(guān)于使用MultiSelectList的文章,并且還沒有理解我的DropDownListFor到底出了什么問題。我有一個(gè)ListBoxFor,它具有相同的視圖、視圖模型和數(shù)據(jù),運(yùn)行良好。我想使用DropDownListFor,因?yàn)樗膐ptionLabel參數(shù)沒有ListBoxFor。當(dāng)首次加載視圖時(shí),DropDownListFor和ListBoxFor都會(huì)顯示多個(gè)選定項(xiàng)。單擊Submit按鈕時(shí),所選項(xiàng)集合將回發(fā)到Controller操作OK,視圖將被刷新,ListBoxFor仍然顯示兩個(gè)選定項(xiàng),但DropDownListFor僅顯示一個(gè)選定項(xiàng)。控制器操作是像這樣構(gòu)造MultiSelectList:vm.TasksFilterGroup.Assignees = new MultiSelectList(employees, "Id", "FullName", new string[]
{ "51b6f06a-e04d-4f98-88ef-cd0cfa8a2757", "51b6f06a-e04d-4f98-88ef-cd0cfa8a2769" });視圖代碼如下所示:<div class="form-group"> <label>ListBoxFor</label> @Html.ListBoxFor(m => m.TasksFilterGroup.SelectedAssignees, Model.TasksFilterGroup.Assignees, new { @class = "form-control", multiple = "multiple" })</div><div class="form-group"> <label>DropDownListFor</label> @Html.DropDownListFor(m => m.TasksFilterGroup.SelectedAssignees, Model.TasksFilterGroup.Assignees, new { @class = "form-control", multiple = "multiple" })</div>為什么DropDownListFor在提交后失去了多個(gè)選擇,而ListBoxFor卻沒有?
- 1 回答
- 0 關(guān)注
- 224 瀏覽
添加回答
舉報(bào)
0/150
提交
取消