Created
September 4, 2020 14:34
-
-
Save bjornmicallef/dd0fca3303ce7742965fac61ea5e9c52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public JsonResult GetCountries(string selectedValue) | |
{ | |
countries = new List(); | |
countries.Add(new SelectListItem { Text = "Select country", Value = "0" }); | |
switch (selectedValue) | |
{ | |
case "1": | |
countries.Add(new SelectListItem { Text = "United Kingdom", Value = "1" }); | |
countries.Add(new SelectListItem { Text = "Italy", Value = "2" }); | |
countries.Add(new SelectListItem { Text = "Greece", Value = "3" }); | |
break; | |
case "2": | |
// more countries | |
break; | |
case "3": | |
// more countries | |
break; | |
} | |
return Json(new SelectList(countries, "Value", "Text")); | |
} | |
public JsonResult GetCities(string selectedValue) | |
{ | |
cities = new List(); | |
cities.Add(new SelectListItem { Text = "Select city", Value = "0" }); | |
switch (selectedValue) | |
{ | |
case "1": | |
cities.Add(new SelectListItem { Text = "Glasgow", Value = "1" }); | |
cities.Add(new SelectListItem { Text = "London", Value = "2" }); | |
cities.Add(new SelectListItem { Text = "Edinburgh", Value = "3" }); | |
break; | |
case "2": | |
// more cities | |
break; | |
case "3": | |
// more cities | |
break; | |
case "4": | |
// more cities | |
break; | |
case "5": | |
// more cities | |
break; | |
// more cases | |
} | |
return Json(new SelectList(cities, "Value", "Text")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment