vortex
vortex

Reputation: 1058

Drop-Down selected item does not get selected

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:

enter image description here

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: enter image description here

So far everything looks good, but when i step on the next line, the selected value gets Selected = falseand my value does not gets selected. Does anybody have an idea why is this happening?

Upvotes: 0

Views: 255

Answers (1)

user3559349
user3559349

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

Related Questions