国のコントロールのための2つのdropdoenlistforがあります。& City.So選択した国に基づいて都市のドロップダウンリストをバインドしたいと思います。どうすればこれを達成できますか?ここDropDownListForでの呼び出しアクションMVCでの選択
が私のコードである
AirportController.cs
// GET: Airport/Create
public ActionResult Create()
{
List<City> lstCity = new DACity().GetListAll();
ViewBag.City = lstCity;
List<Country> lstCountry = new DACountry().GetListAll();
ViewBag.Country = lstCountry;
return View();
}
Create.cshtml
<div class="form-group">
@Html.LabelFor(model => model.CountryID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.CountryID, new SelectList(ViewBag.Country, "CountryID", "CountryName"), "--select--", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CountryID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CityID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.CityID, new SelectList(ViewBag.City, "CityID", "CityName"), "--select--", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CityID, "", new { @class = "text-danger" })
</div>
</div>
使用を 'データを引き出すために「ajax」を使用します。 –
市のデータを取得するにはjqueryを使用してください。このリンクを参考にしてください。http://www.advancesharp.com/blog/1145/mvc-dropdownlistfor-fill-on-selection-change-of-another-dropdown –
[このDotNetFiddle](https://dotnetfiddle.net/1bPZym)のカスケーディングドロップダウンリストを実装する –