Don't you know how to create multi select drop down list in MVC 5.It is very easy in traditional HTML and ASP.NET webform. But when comes to the MVC it is a little bit difficult.But, binding database values to the dropdown list very easy in MVC compared to HTML.
In normal dropdown list we can allow to select single option from drop down but using multi select list box we can able to select multiple options.
In this tutorial i am going to share you how to populate multi select drop down List in mvc by comparing normal dropdown list.
Step 1: create an ASP.NET MVC web application
1.Add Controller name it as HomeController.cs
2.Create action method Index()
Step 2: create data source for drop down list
1.create List data to populate a drop down.
2.Replace Index action with following code.
Step 3:Prepare data for multi select listbox
1.Here i created a GetCountries() method with type as 'MultiSelectList'.
2.Data for Multi select drop down List box comes from here.
3.I passed this data using ViewBag to Index view in Index Action Method.You can see the code in first code snippet.
Step 4:Create Index View
1.Right click on Index action -->Add View-->click ok
2.Index view created .
3.Replace the Index view code with following code
Now run the application and see browser window.
we can select multiple values by pressing CTRL select.
I hope every reader understand this tutorial.If you recommend any modification please let me know to increase the readability of this article.