Tuesday, December 1, 2015

MVC Drop Down Lists and Selects

This is the most concise way to do it:


ASP.Net MVC 4 DropDownList Example

1. First of all, we will assume you know how to create a new MVC project in MS 2012, in case you need guide, please refer to here. Please create a project and name itDropDownList.
2. It’s recommended that we bind data with strongly type model, so that we could spot the error in design time. Now create a View Model folder and in this folder add a class name Programming.cs and this class will going to help us to bind data into view. Copy this code into Programming.cs.
3. Create a controller and name it DropDownList. (Right click on Controllers Folder > Add > Controller). Now we need to prepare for dropdownlist data , go to Controller> DropDownListController.cs then add this code into Index function
4. In the DropDownListController.cs, add view with name index. (Right click on ActionResult > Add View). Then go to Views > DropDownList> Index.chtml. Copy code below and paste into Index.chtml