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.
Upon submit however, the value in the source SelectList is not bound.
Case: ViewData.SearchBag.FamilyCodes:
public SelectList FamilyCodes { get; set; }
Html that generates the dropdown:
<%=Html.DropDownList("SearchBag.FamilyCodes")%>
Generated html:
<select id="SearchBag.FamilyCodes" name="SearchBag.FamilyCodes">
<option value=" ">Any</option>
<option value="A">BLUE</option>
<option value="B">BLACK</option>
<option value="C">BEIGE</option>
<option value="G">GREEN</option>
<option value="O">ORANGE</option>
<option value="P">PURPLE</option>
<option value="R">RED</option>
<option value="S">GRAY</option>
<option value="U">BROWN</option>
<option value="W">WHITE</option>
<option value="Y">YELLOW</option>
</select>
In my controller I have an action with a parameter searchBag.
public ActionResult AdvancedSearch(SearchBag searchBag) {
//Do Stuff with parameters in searchBag
return View("AdvancedSearch", searchViewData);
}
All other fields bind just fine, only the selection boxes don't. Any ideas?
UPDATE
For future readers it might be worth it to read this blog post: http://haacked.com/archive/0001/01/01/model-binding-to-a-list.aspx