I'm using ASP.NET MVC 2.0, but apparently this was a problem in MVC 3.0 as well.
Basically if you have a "complex" property name, then Html.DropDownListFor
does not set any SelectListItem.Selected = true
.
So this works (where ViewData.States
is IEnumerable<SelectListItem>
).
<td><%= Html.DropDownListFor( m => m.State, ViewData.States ) %></td>
But this does not:
<td><%= Html.DropDownListFor( m => m.CaseFields[i].State, ViewData.States ) %></td>
I saw this QA where the answerer correctly explained the problem, however his solution of using SelectList
as the argument to DropDownListFor
does not work in my case - I get the exact same result (loads of <option>
elements but not a single selected="selected"
attribute).
I'm tempted to reimplement DropDownListFor
, but if anyone knows a workaround I'd love to hear it!