When I edit record country list is loaded but the city list not loaded. For example, I have saved record Country USA and City are Newyork is not loaded if the USA country selected. This function works well when I add new Add Record But Edit I use in Edit Operation I have the Problem.
C#
- List<Country> listCountry = _ICountry.listofCountry();
- ViewBag.CountryList = new SelectList(listCountry, "CountryID", "CountryName");
-
- public JsonResult GetCity(int CountryID)
- {
- List<City> ctyList = _ILogin.GetCityList(CountryID);
- return Json(ctyList, JsonRequestBehavior.AllowGet);
-
- }
- <div class="row">
- <div class="col-md-6">
- <label class="col-xs-3 control-label">Country</label>
- <div class="controls col-xs-9">
- @Html.DropDownListFor(m => m.CountryID, ViewBag.CountryList as SelectList, "Choose the Country Name", new { @class = "input-border-btm" })
-
- </div>
- </div>
- <div class="col-md-6">
- <label class="col-xs-3 control-label">City</label>
- <div class="controls col-xs-9">
- @Html.DropDownListFor(m => m.CityID, new SelectList(" "), "Choose City", new { @class = "input-border-btm" })
-
- </div>
- </div>
- </div>
Jquery
- <script>
- $(document).ready(function () {
- $("#CountryID").change(function () {
- $.get("/Items/GetCity", { CountryID: $("#CountryID").val() }, function (data) {
- $("#CityID").empty();
- $.each(data, function (index, row) {
- $("#CityID").append("<option value='" + row.CityID + "'>" + row.CityName + "</option>")
- });
- });
- })
- });
- </script>