我在 html 中有一个 2 Dropdownlistfor,用于 Country 的 dropdownlist 和用于 state 的 dropdownlist。我使用 MVC,我想成为这样的输出,如果我更改 Selected Country,所选国家的 state 将填充到 state 的下拉列表中。我从数据库中获取国家和州的数据,并且在州表中有一个 countryId 字段。感谢帮助。
这是 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>