In this article, you will learn how to create a cascading DropDownList in ASP.NET MVC. I will show you the procedure step-by-step. So, let's begin.
Case Study: I will create two DDLs (State and District). The first DDL will let you pick a state and when you a pick state, it will make a parameterized JSON call using jQuery that will return a matching set of districts that will be populated to the second DDL. I will also show how to use proper validations with each control. Here is the animated screen that we are going to create:
Now, let's see the procedure.
Step 1
At the very first, we need a model class that defines the properties for storing data.
- public class ApplicationForm
- {
- public string Name { get; set; }
- public string State { get; set; }
- public string District { get; set; }
- }
Step 2
Now, we need an initial controller that will return an Index view by a packing list of states in ViewBag.StateName.
- public ActionResult Index()
- {
- List<SelectListItem> state = new List<SelectListItem>();
- state.Add(new SelectListItem { Text = "Bihar", Value = "Bihar" });
- state.Add(new SelectListItem { Text = "Jharkhand", Value = "Jharkhand" });
- ViewBag.StateName = new SelectList(state, "Value", "Text");
- return View();
- }
In the above controller we have a List<SelectListItem> containing states attached to ViewBag.StateName. We could get a list of states from the database using a LINQ query or something and pack it into ViewBag.StateName. Well let's go with in-memory data.
Step 3
Once we have a controller we can add its view and start creating a Razor form.
- @Html.ValidationSummary("Please correct the errors and try again.")
- @using (Html.BeginForm())
- {
- <fieldset>
- <legend>DropDownList</legend>
- @Html.Label("Name")
- @Html.TextBox("Name")
- @Html.ValidationMessage("Name", "*")
- @Html.Label("State")
- @Html.DropDownList("State", ViewBag.StateName as SelectList, "Select a State", new { id = "State" })
- @Html.ValidationMessage("State", "*")
- @Html.Label("District")
- <select id="District" name="District"></select>
- @Html.ValidationMessage("District", "*")
- <p>
- <input type="submit" value="Create" id="SubmitId" />
- </p>
- </fieldset>
- }
You can see I have added proper labels and validation fields with each input control (two DropDownLists and one TextBox) and also a validation summery at the top. Notice, I have used <select id="District"….> which is HTML instead of a Razor helper; this is because when we make a JSON call using jQuery we will return HTML markup of the pre-populated option tag. Now, let's add jQuery code in the above view page.
Step 4
Here is the jQuery code making a JSON call to the DDL named controller's DistrictList method with a parameter (which is the selected state name). The DistrictList method will return JSON data. With the returned JSON data we are building <option> tag HTML markup and attaching this HTML markup to "District" which is a DOM control.
- @Scripts.Render("~/bundles/jquery")
- <script type="text/jscript">
- $(function () {
- $('#State').change(function () {
- $.getJSON('/DDL/DistrictList/' + $('#State').val(), function (data) {
- var items = '<option>Select a District</option>';
- $.each(data, function (i, district) {
- items += "<option value='" + district.Value + "'>" + district.Text + "</option>";
- });
- $('#District').html(items);
- });
- });
- });
- </script>


Tasneem NomaniPosted Feb 11, 2024, 12:48 AM
How to set default state and district initially
Satya MaruthiPosted Apr 8, 2022, 10:59 AM
Very helpful. I would like to post the selected list values to the controller. I have a problem with the posting second list value. Any idea would be helpful. Thanks in advance.
Rich StrikerPosted Apr 20, 2021, 12:41 PM
Most confusing code example I have ever seen....get a clue.
Raymond GPosted Apr 10, 2020, 4:47 AM
Dear Sourabh thanks for this description that helped me to understand cascaded dropdownlist. I am trying to apply Bootstrap 3 functionality : @using (Html.BeginForm()), <div class="form-horizontal">, Class = "form-control".When the view initialize the display is ok and Bootstrap applied, unfortunately when the City dropdownlist is updated I loose City dropdownlist Bootstrap formatting. is there any guidance you can give to fix this. Thanks a lot.
Padmakhi SahuPosted Feb 17, 2018, 11:12 PM
Sir please help me figure out how to use cascading dropdownlist for state and city to insert data and in edit view page
Kishore MadanapaliPosted Oct 30, 2017, 6:49 AM
Sir please post an example of Cascading dropdownlist in asp.net mvc using jquery and ado.net code. Eg:Countries,States,Cities
Sourabh MishraPosted Oct 6, 2017, 6:44 AM
Video on cascading dropdownlist using angularjs https://www.youtube.com/watch?v=Bw9PrDykDxI
rehab aliPosted Oct 4, 2017, 8:30 AM
Thank you, it was easy Could you please share the code for a three level cascade i trying but not work
Yash BhanPosted Jun 20, 2017, 9:53 AM
Thank you so much for this! Could you please share the code for a three level cascade?
Deepak ChoudharyPosted May 29, 2017, 8:43 AM
@Html.DropDownListFor(x => x.StateNames, Model.StateNames, "--Select--", new { @id="ddlState"}); show error pls give me solution (StateNames)
Manav PandyaPosted May 18, 2017, 1:42 AM
Nice one ......................
likhitha valliPosted May 9, 2017, 2:41 AM
I am using kendo dropdownlist the text is not binding to kendo dropdown
rucha kinikarPosted Mar 1, 2017, 11:48 AM
I want to know,how to featch the value on text box when we select the the value from dropdown box I.e using script ?
imran bhattiPosted Dec 24, 2016, 1:03 AM
The code is good but i am not able to populate the second Dropdownlist only first one is populating.
Zeeshan AzimPosted Jan 25, 2016, 6:05 AM
Thousands of thanks for this snippet.
Ankur MistryPosted Jan 9, 2016, 1:58 AM
good one
Praveen DhatrikaPosted Jan 8, 2016, 3:12 PM
Thnq It helped me a lot. :)
Rupali ShindePosted Jan 8, 2016, 3:54 AM
really nice example of cascading dropdown
Mukesh KumarPosted Nov 9, 2015, 5:52 AM
Good One
Ajay KadamPosted Oct 20, 2015, 2:43 AM
NIce it works...Thanks
malusi ngubanePosted Aug 15, 2015, 10:14 AM
cascading is good but how to save those selected values to the database
Jefferson BritoPosted May 11, 2015, 1:10 PM
How can I populate the dropdownlist in edit mode?
Manish Kumar ChoudharyPosted Jan 3, 2015, 11:57 PM
Nice one..