I am trying to set the selected values for the MultiSelectList, but the page does not display the values selected. I tried every practical way to do this and still get the same results. I am currently trying to pass a list of selected objects through a constructor. I'm interested in the fact that when I check the MultiSelectList object, the selectedvalues property contains elements that I passed to it using the constructor, but it still does not show.
I noticed that many people have the same problem, but I did not see the answer that worked for me. I tried to iterate through the list and set the selected property to true, I tried to create a list of multiselects from scratch and set the selected property for each individual element, and I tried to use the constructor. None of them worked. I also found a suggestion that the MultiSelectList property cannot be called the same as the control (which I tried), and this did not work. Sincerely, why is it so difficult to create a drop-down list with selected values using this structure? Did I miss something?
State Practice:
<% = Html.ListBox ("StatesOfPractice", Model.StatesOfPracticeList)%>
<% = Html.ValidationMessage ("StatesOfPractice")%>
EDIT NO. 1
It seems to happen when I create an instance of MultiSelectList. If I examine the object in the view and open the view of the results, I see that Alaska is not selected when I know what it should be.
http://imgur.com/eTIdH.jpg
I create an instance this way.
new MultiSelectList (list, "code", "description", "list");
GenericDataContract is just a class with two properties: Code and Description. The first list is all the states, the second list is my selected states.
selected asp.net-mvc multi-select
jamesamuir
source share