Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET MVC MultiSelectList and selected values
    primarykey
    data
    text
    <p>I am trying to set the selected values for a MultiSelectList but the page does not display any values as selected. I have tried every practical way to do this and still get the same results. I am currently trying to pass a list of selected objects in via the constructor. What gets me is that when I inspect MultiSelectList object, the selectedvalues property contains the items that I have passed into it using the constructor but it still does not display. </p> <p>I have noticed that many people are having the same problem but I have not seen an answer that has worked for me. I have tried iterating through the list and setting the selected property to true, I have tried creating the multiselectlist from scratch and setting each individual items selected property and I have tried using the constructor. None of these have worked. I also found an a suggestion that the MultiSelectList property could not be named the same as the control (which I tried) and that did not work. Why is it so difficult to create a dropdown list with selected values using this framework? Am I missing something?</p> <pre><code>&lt;label for="StatesOfPractice"&gt;States of Practice:&lt;/label&gt; &lt;br /&gt; &lt;%= Html.ListBox("StatesOfPractice", Model.StatesOfPracticeList)%&gt; &lt;br /&gt; &lt;%= Html.ValidationMessage("StatesOfPractice")%&gt; </code></pre> <h2>Edit 1</h2> <p>It appears to be happening when I instantiate the MultiSelectList. If I inspect the object in the View and open the Results View I can see that "Alaska" is not selected when I know that it should be. </p> <p><a href="https://imgur.com/eTIdH.jpg" rel="nofollow noreferrer">http://imgur.com/eTIdH.jpg</a></p> <p>I am instantiating like this. </p> <pre><code>new MultiSelectList(List&lt;GenericDataContract&gt;, "Code", "Description", List&lt;GenericDataContract&gt;); </code></pre> <p>The GenericDataContract is simply a class with two properties, Code and Description. The first List is all of the states, the second List is my selected states.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload