Добавить адрес автозаполнения
У меня проблема с кодом. Результатов не найдено Я заполняю форму заявки на вакансию.
Контроллер
public JsonResult Getprovinces()
{
List<mydistrict> provincel = new List<mydistrict>();
provincel = (from p in _auc.mytable
select p).ToList();
return Json(provincel);
}
public JsonResult Getamphoes(int province_code)
{
List<mydistrict> amphoelist = new List<mydistrict>();
amphoelist = (from Provinces in _auc.mytable
where Provinces.province_code == province_code
select Provinces).ToList();
return Json(amphoelist);
}
public JsonResult Getdistrict(int province_code, string amphoe_code)
{
List<mydistrict> districtslist = new List<mydistrict>();
districtslist = (from district in _auc.mytable
where district.province_code == province_code
where district.amphoe_code == amphoe_code
select district).ToList();
return Json(districtslist);
}
public JsonResult detail(int province_code, string amphoe_code,string district_code)
{
List<mydistrict> detail = new List<mydistrict>();
detail = (from de in _auc.mytable
where de.province_code == province_code
where de.amphoe_code == amphoe_code
where de.district_code == district_code
select de).ToList();
return Json(detail);
}
просмотр
<select id="mydistrict_province" onchange="showAmphoes()" class="form-control">
<option value=""></option>
</select><br />
<select id="mydistrict_amphoe" onchange="showDistricts()" class="form-control">
<option value=""></option>
</select><br />
<select id="mydistrict_district" onchange="showZipcode()" class="form-control">
<option value=""></option>
</select><br />
<input id="mydistrict_zipcode" class="form-control" />
скрипт
$(document).ready(function () {
showProvinces();
});
function showProvinces() {
var url = '@Url.Content("~/")' + "Employee/Getprovinces";
var callback = function (result) {
$("#mydistrict_province").empty();
for (var i = 0; i < result.length; i++) {
$("#mydistrict_province").append(
$('<option></option>')
.attr("value", "" + result[i].province_code)
.html("" + result[i].province)
);
}
showAmphoes();
};
ajax(url, callback);
}
function showAmphoes() {
var province_code = $("#mydistrict_province").val();
var url = '@Url.Content("~/")' + "Employee/Getamphoes";
var callback = function (result) {
console.log(result);
$("#mydistrict_amphoe").empty();
for (var i = 0; i < result.length; i++) {
$("#mydistrict_amphoe").append(
$('<option></option>')
.attr("value", "" + result[i].amphoe_code)
.html("" + result[i].amphoe)
);
}
showDistricts();
};
ajax(url, callback);
}
function showDistricts() {
var province_code = $("#mydistrict_province").val();
var amphoe_code = $("#mydistrict_amphoe").val();
var url = '@Url.Content("~/")' + "Employee/Getdistrict";
var callback = function (result) {
$("#mydistrict_district").empty();
for (var i = 0; i < result.length; i++) {
$("#mydistrict_district").append(
$('<option></option>')
.attr("value", "" + result[i].district_code)
.html("" + result[i].district)
);
}
showZipcode();
};
ajax(url, callback);
}
function showZipcode() {
var province_code = $("#mydistrict_province").val();
var amphoe_code = $("#mydistrict_amphoe").val();
var district_code = $("#mydistrict_district").val();
var url = '@Url.Content("~/")' + "Employee/Getdetail";
var callback = function (result) {
for (var i = 0; i < result.length; i++) {
$("#mydistrict_zipcode").val(result[i].zipcode);
}
};
ajax(url, callback);
}
function ajax(url, callback) {
$.ajax({
"url": url,
"type": "GET",
"dataType": "json",
})
.done(callback);
}
Результат введите описание изображения здесь
Помогите пожалуйста, спасибо