Reputation: 1058
I know there are number of similar qustions around here, but non of the solutions helped me with this. Here is my case:
I have a List in my model.
public List<SelectListItem> Layouts { get; set; }
After my "Load" method, the result is as follows:
Then in my view i use this overload:
@Html.DropDownListFor(x => x.Layout, Model.Layouts, "Select a Layout",
new { @id = "ddLayouts", @onchange = "javascript:getExampleAddresses(this.value);" })
Stepping on that exact line with debbuger, i get the following result:
So far everything looks good, but when i step on the next line, the selected value gets Selected = false
and my value does not gets selected. Does anybody have an idea why is this happening?
Upvotes: 0
Views: 255
Reputation:
You strongly binding to property Layout
The value of Layout
determines what is selected, not the Selected
property of SelectListItem
(its ignored).
Set the value of Layout
in the controller to match the value of one of the options and that option will be selected in the view
Upvotes: 3