Model with collection - Html.ListBoxFor doesn't set selected items

萝らか妹 提交于 2019-12-07 04:48:27

SelectList only supports a single selected value, so in your code examples you're telling it to set the selected value as the option which has a value of the entire list of selected values. Since no such option exists, nothing is selected.

MultiSelectList on the other hand, allows passing an enumerable of selected values. If you use the right class, you'll be okay.

@Html.ListBoxFor(m => item.SelectedClassifications, new MultiSelectList(Model.AllClassifications, "ID", "Title", item.SelectedClassifications))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!