Redone
Redone

Reputation: 1303

How to select multiple items from dropdown list, save it and again repopulate the dropdown with the selected list?

I am working on an ASP.NET MVC3 project. I am facing issues regarding multiple selection in dropdown.

The problem is, I have to save multiple items in database from a dropdown list and repopulate it.

I have used the class below to represent each list data:

public class IDNameValueTO {
    public int ID { get; set; } //Value of the selection Element
    public string Name { get; set; } //Name of the selectionElement
    public int Value { get; set; } //1 if value is checked and 0 if not
}

My List goes as follows:

public List<IDNameValueTO> tempList = new List<IDNameValueTO>();
ViewBag.SelectedList = tempList;

I am generating the dropdown list as follows:

@Html.DropDownList("SelectedValue", new SelectList(ViewBag.SelectedList, "ID", "Name"))

Now how do I save the multiple selection and display it later on using dropdown?

Upvotes: 1

Views: 6107

Answers (1)

CoffeeCode
CoffeeCode

Reputation: 4314

The default DropDown helper that is provide in asp.net mvc does not support multiselet.

You'll have to create your own custom multiselect dropdown helper.

Here are some links that can help you create you own custom dropdown helper:

Upvotes: 2

Related Questions