[英]ASP.NET MVC MultiSelectList selected item does not work
I trying to use the MultiSelectList
in ASP.NET MVC with selected items.我尝试将 ASP.NET MVC 中的MultiSelectList
与选定项目一起使用。
This is the backend code:这是后端代码:
var listPoles = new List<long>();
foreach (var pole in employeePole.PolesList)
listPoles.Add(pole.Id);
ViewBag.poles = new MultiSelectList(GetPoles(), "Id", "Name", listPoles);
GetPoles()
returns IReadOnlyList
. GetPoles()
返回IReadOnlyList
。
HTML code (view): HTML 代码(查看):
<select multiple="multiple" title="selecione..." class="form-control selectpicker" id="poles" asp-for="@Model.Poles" asp-items="@ViewBag.poles"></select>
In edit view (front-end) the select component does not load the selected items but I used the exactly same code (with different entity) in another CRUD in the same system and it works fine.在编辑视图(前端)中,select 组件不会加载所选项目,但我在同一系统的另一个 CRUD 中使用了完全相同的代码(具有不同的实体),它工作正常。
I tried to use a lot of different types of collection (enumerable, readonlylist, list, etc) to create the selected items list but nothing works我尝试使用许多不同类型的集合(可枚举、只读列表、列表等)来创建所选项目列表,但没有任何效果
What can possibly be wrong?什么可能是错的?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.