PDA

View Full Version : سوال: نمایش داده در DropDownList بکمک json



Iran58
پنج شنبه 17 اسفند 1396, 23:15 عصر
سلام
یک DropDownList دارم که می خواهم اسم شهرها را براساس کشوری که از یک DropDownList انتخاب میکنم نمایش بدهم
کد DropDownList کشور بصورت زیر است

<div class="form-group">
@Html.LabelFor(model => model.CountryId, "Country", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("Country", null, "-کشور را انتخاب کنید-", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CountryId, "", new { @class = "text-danger" })
</div>
</div>

درست نمایش میدهد
و کد

public ActionResult LoadCity(int countryId)
{
return Json(db.T_B_City.Where(c => c.ParentId == countryId).Select(s => new
{
Id=s.ID,
Name=s.Name
}).ToList(),JsonRequestBehavior.AllowGet);
}

را هم برای خواندن شهرها نوشته ام
اما نمی دانم DropDownList شهرا چگونه بکمک jquery , gson پر کنم
لطفا راهنمای کنید