Note that there are some explanatory texts on larger screens.

plurals
  1. POModelbinding with SelectList
    text
    copied!<p>I create a DropDown with the Html.DropDownList(string NameSelectListInViewData) method. This generates a valid Select input with the correct values. And all is well.</p> <p>Upon submit however, the value in the source SelectList is not bound. </p> <p><em>Case:</em> ViewData.SearchBag.FamilyCodes:</p> <pre><code>public SelectList FamilyCodes { get; set; } </code></pre> <p>Html that generates the dropdown:</p> <pre><code>&lt;%=Html.DropDownList("SearchBag.FamilyCodes")%&gt; </code></pre> <p>Generated html:</p> <pre><code>&lt;select id="SearchBag.FamilyCodes" name="SearchBag.FamilyCodes"&gt; &lt;option value=" "&gt;Any&lt;/option&gt; &lt;option value="A"&gt;BLUE&lt;/option&gt; &lt;option value="B"&gt;BLACK&lt;/option&gt; &lt;option value="C"&gt;BEIGE&lt;/option&gt; &lt;option value="G"&gt;GREEN&lt;/option&gt; &lt;option value="O"&gt;ORANGE&lt;/option&gt; &lt;option value="P"&gt;PURPLE&lt;/option&gt; &lt;option value="R"&gt;RED&lt;/option&gt; &lt;option value="S"&gt;GRAY&lt;/option&gt; &lt;option value="U"&gt;BROWN&lt;/option&gt; &lt;option value="W"&gt;WHITE&lt;/option&gt; &lt;option value="Y"&gt;YELLOW&lt;/option&gt; &lt;/select&gt; </code></pre> <p>In my controller I have an action with a parameter searchBag.</p> <pre><code>public ActionResult AdvancedSearch(SearchBag searchBag) { //Do Stuff with parameters in searchBag return View("AdvancedSearch", searchViewData); } </code></pre> <p>All other fields bind just fine, only the selection boxes don't. Any ideas?</p> <p><em>UPDATE</em><br> For future readers it might be worth it to read this blog post: <a href="http://haacked.com/archive/0001/01/01/model-binding-to-a-list.aspx" rel="nofollow noreferrer">http://haacked.com/archive/0001/01/01/model-binding-to-a-list.aspx</a></p>
 

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