Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DropDownlist preselect multiple items

I want to preselect (from my controller) multiple options in a list. I've tried almost everything, but I am not able to get the items selected.

What's wrong with this?

@Html.DropDownListFor(x=>x.UserIds, Model.Users, new { @class = "form-control input-sm chosen", multiple = "multiple"})

I've also tried @Html.DropdownList() - without success.

Everything seems to be fine in my model. The selectlist has a selected item and the item's selected property is true, but I only get unselected options.

SelectedValue SelectedItem Unselected options

like image 827
Jetro223 Avatar asked Dec 03 '25 10:12

Jetro223


1 Answers

Use @Html.ListBox or @Html.ListBoxFor instead of @Html.DropDownList

like image 51
Jetro223 Avatar answered Dec 07 '25 14:12

Jetro223



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!