为什么DropDownListFor在提交后失去了多个选择,而ListBoxFor却没有?

为什么DropDownListFor在提交后失去了多个选择,而ListBoxFor却没有?

我读过许多关于使用MultiSelectList的文章,并且还没有理解我的DropDownListFor到底出了什么问题。我有一个ListBoxFor,它具有相同的视图、视图模型和数据,运行良好。我想使用DropDownListFor,因为它的optionLabel参数没有ListBoxFor。

当首次加载视图时,DropDownListFor和ListBoxFor都会显示多个选定项。

单击Submit按钮时,所选项集合将回发到Controller操作OK,视图将被刷新,ListBoxFor仍然显示两个选定项,但DropDownListFor仅显示一个选定项。

控制器操作是像这样构造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在提交后失去了多个选择,而ListBoxFor却没有?



收到一只叮咚
浏览 198回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP