JavaScript
<script>
$(document).ready(function () {
$("#StateId").change(function () {
$("select[id$=CityId] > option").remove();
var StateId = $('#StateId').val();
if (StateId > 0) {
$.ajax({
url: '/Emp/GetAllCity',
type: 'GET',
datatype: JSON,
data: StateId,
success: function (data) {
debugger;
//alert('data:' + JSON.stringify(data));
for (var i = 0; i < data.length; i++) {
$("#CityId").append('<option value="'+data[i].CityId + '">' + data[i].CityName + '</option>');
}
},
error: function (data) { }
});
}
}).change();
});
Метод действия:
public JsonResult GetAllCity(int CityId)
{
EmpRepo empRepo = new EmpRepo();
List<City> lstCity = new List<City>();
lstCity = empRepo.GetCity(CityId);
return Json(lstCity, JsonRequestBehavior.AllowGet);
}