I have this annoying problem where my DropDownlist doesn\'t select the current value by default.
Controller:
var YearsCycling = new SelectList(new Li
If you are rendering your list like this: @Html.DropDownListFor(model => model.EntityID, Model.EntitySelectList)
The value .NET MVC will use when rendering the select options will match the value of model.EntityID.ToString()
.
... It will not select the Model.EntitySelectList.SelectedValue
... Or any of the EntitySelectList.Item.SelectedValue
items.
... In other words, when rendering a DropDownListFor something other than the list itself, the SelectedValue properties of both the List and the List Items are ignored.
No matter what Model.EntitySelectList.SelectedValue or Model.EntitySelectList.Item.SelectedValue is set, ASP.NET MVC will not render selection. Use the model.EntityID
instead.