Binoy Kumar
Binoy Kumar

Reputation: 432

How to pre populate chosen multiselct dropdown on edit

I am using chosen multiselect drop down in my sample project

@Html.DropDownListFor(m => m.SelectedBranch, Model.BranchList, "Select", new { @class = "select-chosen form-control", @tabindex = "2", @id = "BranchId", @multiple = "multiple" })

and my model is

public string[] SelectedBranch { get; set; }
public IEnumerable<SelectListItem> BranchList { get; set; }

The issue I am facing is I am not able to display the selected values on editing the already added data. I am getting all the selected values from the db in Cntroller

. Please let me know what I have to do to achieve it. Any help will be appreciated. Thanks

Upvotes: 1

Views: 1725

Answers (1)

user3559349
user3559349

Reputation:

You need to use ListBoxFor() (and without new { multiple="multiple" }) to generate a multiple select that binds to your model

@Html.ListBoxFor(m => m.SelectedBranch, Model.BranchList, "Select", new { @class = "select-chosen form-control", @tabindex = "2", @id = "BranchId" })

Upvotes: 2

Related Questions