Hi
Below is the code
function FillCity() {
var stateId = $('#StateId').val();$.ajax({
url: '/Customer/GetCity',
type: "GET",
dataType: "JSON",
data: { StateId: stateId },
success: function (cities) {$("#CityId").html(""); // clear before appending new list$.each(cities, function (i, city) {$("#CityId").append($('<option></option>').val(city.CityId).html(city.CityName));
});
},
error: function (xhr, ajaxOptions, thrownError) {$("#errorModalBody").html('Status : ' + xhr.status + ' Error : ' + thrownError);$("#errorModal").modal('show');
}
});
}
Controller
public ActionResult GetCity(int StateId)
{
var cities = db.Cities.Where(c => c.StateId == StateId);
return Json(cities, JsonRequestBehavior.AllowGet);
}Thanks