Hello every one welcome again.Thank you all for your response for previous post.To day post i am going to explain "How to implement option Group support DropdownList in ASP.NET MVC application.
Description: In HTML "optgroup " tag groups related options in Drop down list.The Grouping of options is helpful when you have more options and group of options in drop down list.
In HTML markup we implement option group drop down list like this,
Now we are going to do the same dropdown list using ASP.NET MVC .
Create an MVC web application.
1.Open Visual studio 2013.
2.Goto File menu-->New-->Project.
3.Select "ASP.NET web template" from installed templates.
4.Name the project and select location.
5.Select Empty MVC template.
5.Select MVC checkbox to add MVC folder structure.
Prepare a Model in Models folder
2. Replace code with following code.
1.Right click on Controllers folder-->Add-->Controller
2.Name it as HomeController.cs (For demo purpose).
Prepare the Data source for Drop down list in Controller.
Note: In this tutorial i created data source in Controller but in real time we use Data Access Layers for getting Database data.
1.I prepared the data source for dropdownlist in Controller.
Create UI for Drop down list in Index View
1.Right click Index Action-->Add View.
2.In Add View window wizard click Add button.
3.Replace the Index code with following code.
Now Run the application Press F5.
we will get Option Group Drop down list like this.
The selected Value will be displayed like below.
I hope you all understand my tutorial .if you recommend any modifications please suggest me.