Today, in this article, I will explain how to create a cascading dropdown list using MVC, Web API, and jQuery. Here, I am using three tables - Country, State, and City - respectively. If we select a country, then it should display country related states and when we select a state, it should display state-related cities. Finally, here, we will use MVC, Web, jQuery, and SQL Server. So now, let us see the required steps.
Step 1
We have to create three tables - Country, State, and City.

Step 2
Now, we need to create an MVC application but we will create two projects here - one is Web API project for the creation of service and the other one is MVC project for consuming that service. So now, let us add the first MVC project.
Open Visual Studio and go to File->New ->Web application ->select MVC ->OK.

Step 3
Now, add tables in web API project using Entity Framework. So for this, go to Models folder ->right-click -> Add -> New item -> ADO.NET Entity Data Model -> click Add -> select database first approach->click Next.
Select "New Connection" and give the connection details, then select database -> click OK.
Choose tables and click OK.

Step 4
Now, we will write the logic for binding the Country, State and City, So, I create a folder Business Logic and take a class CascadingLogic.cs and write the logic.

public class CascadingLogic
{
JobPortalEntities dbEntity = new JobPortalEntities();
public List<Country> BindCountry()
{
this.dbEntity.Configuration.ProxyCreationEnabled = false;
List<Country> lstCountry = new List<Country>();
try
{
lstCountry = dbEntity.Countries.ToList();
}
catch (Exception ex)
{
ex.ToString();
}
return lstCountry;
}
public List<State> BindState(int countryId)
{
List<State> lstState = new List<State>();
try
{
this.dbEntity.Configuration.ProxyCreationEnabled = false;
lstState = dbEntity.States.Where(a => a.CountryId == countryId).ToList();
}
catch (Exception ex)
{
ex.ToString();
}
return lstState;
}
public List<City> BindCity(int stateId)
{
List<City> lstCity = new List<City>();
try
{
this.dbEntity.Configuration.ProxyCreationEnabled = false;
lstCity = dbEntity.Cities.Where(a => a.StateId == stateId).ToList();
}
catch (Exception ex)
{
ex.ToString();
}
return lstCity;
}
}
After that, we will add an API Controller.

Now, create the API methods and call the methods one by one.
[RoutePrefix("api/Cascading")]
public class CascadingDetailsController : ApiController
{
CascadingLogic objCasc = new CascadingLogic();
[HttpGet]
[Route("CountryDetails")]
public List<Country> BindCountryDetails()
{
List<Country> countryDetail = new List<Country>();
try
{
countryDetail = objCasc.BindCountry();
}
catch (ApplicationException ex)
{
throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = ex.Message });
}
catch (Exception ex)
{
throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadGateway, ReasonPhrase = ex.Message });
}
return countryDetail;
}
[HttpGet]
[Route("StateDetails")]
public List<State> BindStateDetails(int CountryId)
{
List<State> stateDetail = new List<State>();
try
{
stateDetail = objCasc.BindState(CountryId);
}
catch (ApplicationException ex)
{
throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = ex.Message });
}
catch (Exception ex)
{
throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadGateway, ReasonPhrase = ex.Message });
}
return stateDetail;
}
[HttpGet]
[Route("CityDetails")]
public List<City> BindCityDetails(int stateId)
{
List<City> cityDetail = new List<City>();
try
{
cityDetail = objCasc.BindCity(stateId);
}
catch (ApplicationException ex)
{
throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = ex.Message });
}
catch (Exception ex)
{
throw new HttpResponseException(new HttpResponseMessage { StatusCode = HttpStatusCode.BadGateway, ReasonPhrase = ex.Message });
}
return cityDetail;
}
}
Step 5
Now, let's go in MVC project and add a Controller.

After that, create an action method for View and View page.
public ActionResult Details()
{
return View();
}
NOTE
Here, we will not consume the API service using server side, we directly use the client side.
Step 6
Now, we design the page using HTML for cascading Country, State, and City.
<h1>Cascading Dropdown List of Country, State and City</h1>
<hr />
<br />
<div class="row">
<div class="col-lg-3"></div>
<div class="col-lg-6">
<div class="form-group">
<label class="col-md-4 control-label">Country Name</label>
<div class="col-md-6">
<select class="form-control" id="ddlCountry"></select><br />
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">State Name</label>
<div class="col-md-6">
<select class="form-control" id="ddlState"></select>
<br />
</div>
</div>
<br />
<div class="form-group">
<label class="col-md-4 control-label">City Name</label>
<div class="col-md-6">
<select class="form-control" id="ddlCity"></select>
</div>
</div>
</div>
<div class="col-lg-3"></div>
</div>
Output Design

Now, write the jQuery code for consuming and binding the details.
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
var ddlCountry = $('#ddlCountry');
ddlCountry.append($("<option></option>").val('').html('Please Select Country'));
$.ajax({
url: 'http://localhost:54188/api/Cascading/CountryDetails',
type: 'GET',
dataType: 'json',
success: function (d) {
$.each(d, function (i, country) {
ddlCountry.append($("<option></option>").val(country.CountryId).html(country.CountryName));
});
},
error: function () {
alert('Error!');
}
});
//State details by country id
$("#ddlCountry").change(function () {
var CountryId = parseInt($(this).val());
if (!isNaN(CountryId)) {
var ddlState = $('#ddlState');
ddlState.empty();
ddlState.append($("<option></option>").val('').html('Please wait ...'));
debugger;
$.ajax({
url: 'http://localhost:54188/api/Cascading/StateDetails',
type: 'GET',
dataType: 'json',
data: { CountryId: CountryId },
success: function (d) {
ddlState.empty(); // Clear the please wait
ddlState.append($("<option></option>").val('').html('Select State'));
$.each(d, function (i, states) {
ddlState.append($("<option></option>").val(states.StateId).html(states.StateName));
});
},
error: function () {
alert('Error!');
}
});
}
});
//City Bind By satate id
$("#ddlState").change(function () {
var StateId = parseInt($(this).val());
if (!isNaN(StateId)) {
var ddlCity = $('#ddlCity');
ddlCity.append($("<option></option>").val('').html('Please wait ...'));
debugger;
$.ajax({
url: 'http://localhost:54188/api/Cascading/CityDetails',
type: 'GET',
dataType: 'json',
data: { stateId: StateId },
success: function (d) {
ddlCity.empty(); // Clear the plese wait
ddlCity.append($("<option></option>").val('').html('Select City Name'));
$.each(d, function (i, cities) {
ddlCity.append($("<option></option>").val(cities.CityId).html(cities.CityName));
});
},
error: function () {
alert('Error!');
}
});
}
});
});
</script>
Let us run the project but we have to run both projects at one time so for this, so we have to set some changes.
Right-click on the solution project and go to properties. There, check the "Multiple startup projects" option and click "Apply".

Now, we can see the output. It is not giving the expected result but some error.

This error is called CORS. So first, we have to know what CORS is and how to resolve this problem.
According to Wikipedia,
Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the first resource was served.
Now, let us learn how to resolve this problem.
So for this, we have to download CORS in Web API project. Go to NuGet Package Manager and download the following file.

After that, goto App_Start folder in Web API project and then WebApiConfig.cs class. Here, modify the Register method with the below code.
var cors = new EnableCorsAttribute("*", "*", "*");// origins, headers, methods
config.EnableCors(cors);
Now, save changes and run the project to see the final output.
Select a country

Select a state

Thanks! I hope this article was helpful.

Dẫn Dương ĐìnhPosted Jun 20, 2025, 3:16 PM
In the tutorial clip about Cascading Dropdown List Of Country, State And City Using MVC, Web API And jQuery, I want to get the values ??in each dropdown List and save them to another Database Table, how can I do that?
Pranali PatilPosted Jan 24, 2024, 9:24 AM
Ajax call not working
alex smailPosted Aug 28, 2020, 9:05 AM
Like it. but do you know how to display all countries and city in the world?
Rohit MhatrePosted May 25, 2020, 5:41 AM
Follow the link for the answer: https://techstudy.org/mvc/populate-city-dropdown-based-on-state-dropdown
Mark TaborPosted Apr 5, 2019, 5:36 PM
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:58010/api/Cascading/CountryDetails shows resource cannot be found
Mark TaborPosted Apr 5, 2019, 5:20 PM
In MVC controller which action method i need to write and what they would return how the mapping is done between MVC controller and API controller
Mark TaborPosted Apr 5, 2019, 4:44 PM
I am new to web api , I have a question if we have already written the logic in businesslogic class then why we are again writing a method in web api and calling it from that class , if i can omit the business class and write the complete logic in API then what ?
Lae KhamPosted Apr 4, 2019, 12:08 AM
Wow, this is an excellent example and thank you very much for sharing. I am struggling how to pre-select City>State>Country or retrieving after saved to database. Here is what I am trying accomplish. I have another table call Employee that linked to "CityId" of City table, so when "Edit" button selected I would like to pre-select City>State>Country for update. Please help. Thank you very much in advance. Dek Lao
Abdul NasirPosted Sep 23, 2018, 11:08 AM
How can we load datagrid as wel another dropdwonlist with single click of a dropdownlist
Viknaraj ManogararajahPosted Aug 6, 2018, 6:55 PM
nice to thank you for sharing
Metehan MetinPosted Jun 26, 2018, 10:50 AM
How can I apply autocomplete to this dropdowns, would you please explain
Yadu YPosted Jun 13, 2018, 8:09 AM
How to get that data from dropdown box
Diba MadibaPosted Jun 5, 2018, 7:58 AM
Where is the source code for this? It's unreadable in the current state, thanks.
Richard KazimotoPosted May 31, 2018, 2:43 AM
Big up Kumar... You are such a genious... This was straight forward.. So amazing and superb. Worked just fine for me straight away
sumit singhPosted Apr 12, 2018, 2:31 AM
Please do it hurry up
sumit singhPosted Apr 11, 2018, 6:07 AM
Actually i want to know that how to insert data of dropdownlist ??
sumit singhPosted Apr 6, 2018, 8:50 AM
Can u please suggest me the post method code of this page??
Lakshman KPosted Mar 14, 2018, 7:09 PM
It is not working for me, as soon as the page initiates I see the alert popup written for Country dropdown in the cshtml file. I just followed the steps and not sure where exactly went wrong. Able to build with zero errors also, getting the UI page correctly. The issue is with the country list unable to retreive from database. I suspect the error with the URL in the AJAX call code. Please advise.
Naresh SinghalPosted Mar 12, 2018, 11:22 PM
Fantastic, awesome & mind blowing , a perfect article with MVC,API & Jquery....Liked it.....Its Sharply explained....