Я создал вложенный раскрывающийся список, состоящий из списков стран, штатов и городов. В этих списках названия стран и штатов отображаются хорошо, но названия городов не отображаются, хотя я знаю, что мои коды верны.
Спасибо, что помогли мне исправить эту проблему в моем приложение.
Код просмотров:
select>
Код контроллеров:
public IActionResult Create(int id, string lat1, string lng1)
{
List ListProvice = _context.Countries.ToList();
Country model = new Country
{
Id = 1,
NameLaten = "لطفا یک کشور را انتخاب نمایید"
};
ListProvice.Insert(0, model);
ViewBag.ListPrv = ListProvice;
}
[HttpPost]
public IActionResult GetCity(int id)
{
var cityList = _context.Cities.Where(c => c.CountryId == id).Select(c => new { id = c.Id, cname = c.Name }).ToList();
return Json(new { status = "success", cityList });
}
[HttpPost]
public IActionResult GetParesh(int id)
{
var pareshList = _context.Parishes.Where(p =>p.CityId == id).Select(p => new { id = p.Id, cname = p.Name }).ToList();
return Json(new { status = "success", pareshList });
}
Коды JavaScript:
@section mySection {
$("#sltCountry").on('change', function (e) {
if ($("#sltCountry").prop('selectedIndex') == 0) {
$('#divCity').addClass('hidden');
}
else {
//اگر یک کشور انتخاب شده بود
var getid = $('#sltCountry').val();
$.ajax({
type: 'post',
url: '@Url.Action("GetCity","Advert")',
data: { id: getid },
success: function (result) {
if (result.status == "success") {
$('#CityId').empty();
$.each(result.cityList, function (i) {
$('#CityId').append($("")
.val(result.cityList.id).html(result.cityList.cname));
});
}
}
});
$('#divCity').removeClass('hidden');
}
});
$("#divCity").on('change', function (e) {
if ($("#divCity").prop('selectedIndex') == 0) {
$('#divParesh').addClass('hidden');
}
else {
//اگر یک استان انتخاب شده بود
var getid = $('#divCity').val();
$.ajax({
type: 'post',
url: '@Url.Action("GetParesh","Advert")',
data: { id: getid },
success: function (result) {
if (result.status == "success") {
$('#ParishId').empty();
$.each(result.pareshList, function (i) {
$('#ParishId').append($("")
.val(result.pareshList.id).html(result.pareshList.cname));
});
}
}
});
$('#divParesh').removeClass('hidden');
}
});
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... -down-list
Вложенный раскрывающийся список [закрыт] ⇐ C#
Место общения программистов C#
1719244247
Anonymous
Я создал вложенный раскрывающийся список, состоящий из списков стран, штатов и городов. В этих списках названия стран и штатов отображаются хорошо, но названия городов не отображаются, хотя я знаю, что мои коды верны.
Спасибо, что помогли мне исправить эту проблему в моем приложение.
Код просмотров:
select>
Код контроллеров:
public IActionResult Create(int id, string lat1, string lng1)
{
List ListProvice = _context.Countries.ToList();
Country model = new Country
{
Id = 1,
NameLaten = "لطفا یک کشور را انتخاب نمایید"
};
ListProvice.Insert(0, model);
ViewBag.ListPrv = ListProvice;
}
[HttpPost]
public IActionResult GetCity(int id)
{
var cityList = _context.Cities.Where(c => c.CountryId == id).Select(c => new { id = c.Id, cname = c.Name }).ToList();
return Json(new { status = "success", cityList });
}
[HttpPost]
public IActionResult GetParesh(int id)
{
var pareshList = _context.Parishes.Where(p =>p.CityId == id).Select(p => new { id = p.Id, cname = p.Name }).ToList();
return Json(new { status = "success", pareshList });
}
Коды JavaScript:
@section mySection {
$("#sltCountry").on('change', function (e) {
if ($("#sltCountry").prop('selectedIndex') == 0) {
$('#divCity').addClass('hidden');
}
else {
//اگر یک کشور انتخاب شده بود
var getid = $('#sltCountry').val();
$.ajax({
type: 'post',
url: '@Url.Action("GetCity","Advert")',
data: { id: getid },
success: function (result) {
if (result.status == "success") {
$('#CityId').empty();
$.each(result.cityList, function (i) {
$('#CityId').append($("")
.val(result.cityList[i].id).html(result.cityList[i].cname));
});
}
}
});
$('#divCity').removeClass('hidden');
}
});
$("#divCity").on('change', function (e) {
if ($("#divCity").prop('selectedIndex') == 0) {
$('#divParesh').addClass('hidden');
}
else {
//اگر یک استان انتخاب شده بود
var getid = $('#divCity').val();
$.ajax({
type: 'post',
url: '@Url.Action("GetParesh","Advert")',
data: { id: getid },
success: function (result) {
if (result.status == "success") {
$('#ParishId').empty();
$.each(result.pareshList, function (i) {
$('#ParishId').append($("")
.val(result.pareshList[i].id).html(result.pareshList[i].cname));
});
}
}
});
$('#divParesh').removeClass('hidden');
}
});
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78663428/nested-drop-down-list[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия