John
John

Reputation: 747

Html.Dropdownlistfor does not set values

I have multiple dropdown list:

                @Html.DropDownListFor(x => x.HaveColoSpace.SelectedOptions, new SelectList(Model.HaveColoSpace.Options, "Value", "Text"), new { multiple = "multiple" })

where Model.HaveColoSpace.SelectedOptions is List with 2 items ("3" and "5"), Model.HaveColoSpace.Options has List Why items with value "3" and "5" are not pre-selected after loading a page?

Upvotes: 0

Views: 352

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

Use the Html.ListBoxFor helper instead of Html.DropDownListFor if you want to generate a multiselect dropdown list:

@Html.ListBoxFor(
    x => x.HaveColoSpace.SelectedOptions, 
    new SelectList(Model.HaveColoSpace.Options, "Value", "Text")
)

Upvotes: 1

Related Questions