Hello everyone,
Currently I've got three ComboBoxes:
- Country
- State
- City
When user selects a country the next two ComboBoxes will show some values based on the first value. Example:
If country is "United States", the state will show all of the states in the U.S and city will show all of the cities in the U.S.. What I need to do this is to add another condition to select cities based on State if available because not all countries have states.
Following is my code for Cities:
public JsonResult GetCascadeCities(string countries, string states, string cityFilter)
{
var cities = db.GeoDD.AsQueryable();
if (countries != null)
{
cities = cities.Where(p => p.CountryCode == countries);
}
if (!string.IsNullOrEmpty(cityFilter))
{
cities = cities.Where(p => p.City.Contains(cityFilter));
}
return Json(cities.Where(p => p.Deleted == false).Select(p => new { City = p.City }).Distinct().OrderBy(p => p.City), JsonRequestBehavior.AllowGet);
}
So how can I make it so that if a country has state then city should be populated based on Country and State and if not then Country should be the only condition.
Please advice,
Alex