1
我有一個2 Dropdownlistfor html,dropdownlistfor Country和dropdownlistfor狀態。即時通訊使用MVC,我想成爲這樣的輸出,如果我改變選定的國家,所選國家的狀態將被填入下拉列表狀態。我從數據庫中獲取國家和州的數據,而在州表中有一個countryId的字段。感謝幫助。MVC dropdownlist,onchange
這裏是Html示例代碼。
<div class="fieldBlock">
<div><label>Country</label> *</div>
<div>@Html.DropDownListFor(model => model.Country.Id, Model.CountrySelectList, new { @class = "width305", @id = "ddlCountry" })</div>
@Html.HiddenFor(model => model.Country.Name) @Html.HiddenFor(model => model.Country.Abbreviation)
<div>@Html.ValidationMessageFor(model => model.Employee.StateId)</div>
</div>
<div class="fieldBlock">
<div>@Html.LabelFor(model => model.Employee.StateId, "State/Province") *</div>
<div>@Html.DropDownListFor(model => model.Employee.StateId, Model.CountryStateProvinceSelectList, new { @class = "width305" })</div>
<div>@Html.ValidationMessageFor(model => model.Employee.StateId)</div>
</div>
可能的重複[使用Javascript/jQuery動態填充下拉列表](http://stackoverflow.com/questions/7253187/fill-a-drop-down-list-dynamically-using-javascript-jquery) – Rafay
也許你可能會得到更多的幫助,如果你真的問過一個問題,而不是僅僅陳述一堆事情,並期待我們猜測你想要什麼。 –