Вложенный раскрывающийся список [закрыт]C#

Место общения программистов C#
Ответить
Anonymous
 Вложенный раскрывающийся список [закрыт]

Сообщение 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.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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»