I know others have asked this question, but I\'m totally confused by this:
This displays the dropdown with no values selected:
<%= Html.DropDownLi
I had a similar problem, when using ListBoxFor and a MultiSelectList assigned as a ViewBag property. @jero's answer helped me figure out that if there's a naming collision between the ViewBag field and the model field, then the selected values don't appear properly.
If I did the following, the items did not show up as selected.
//Controller
ViewBag.SelectionIds = new MultiSelectView(possibleValues, "Value", "Name", selectedValues);
//View
@Html.ListBoxFor(model => model.SelectionIds, (MultiSelectList)ViewBag.SelectionIds, new { @class = "form-control" })
If I changed it to the following, then it was fine.
//Controller
//Changed ViewBag.SelectionIds to ViewBag.SelectionIdList
ViewBag.SelectionIdList = new MultiSelectView(possibleValues, "Value", "Name", selectedValues);
//View
@Html.ListBoxFor(model => model.SelectionIds, (MultiSelectList)ViewBag.SelectionIdList, new { @class = "form-control" })