HomeController
class Loading extends Component {
constructor(props) {
super(props);
this.state = {isLoading : props.show};
}
componentWillReceiveProps(nextProps) {
this.setState({ isLoading: nextProps.show });
}
render() {
if (this.state.isLoading) {
return (
<div className="loading">
<div className="loading-message">
Carregando...
</div>
</div>);
}
return ('');
}
}
export default Loading;
查看
public JsonResult GetCity(string DistrictID)
{
db.Configuration.ProxyCreationEnabled = false;
cityList = db.Cities.Where(predicate: x => x.DistrictID == DistrictID).OrderBy(x => x.CityName).ToList();
ViewBag.City = cityList.OrderBy(x => x.CityName);
return Json(ViewBag.City, JsonRequestBehavior.AllowGet);
}
此方法返回特定地区内的城市(级联DropdownList)。它正在100%工作。 现在,我想使用类似的逻辑和代码返回基于地区和城市的郊区。我该如何实施? (请包括所有必需的代码,即HomeController,它是View,尤其是jQuery部分)
@Html.LabelFor(m => m.CityID, "City", new { @class = "col-md-3 control-label" })
<div class="col-md-6">
@Html.DropDownListFor(model => model.CityID, new SelectList(" "), "--Select City--", new { @class = "form-control" })
</div>
<script>
$(document).ready(function () {
$("#DistrictID").change(function () {
$.get("/Home/GetCity", { DistrictID: $("#DistrictID").val() }, function (data) {
$("#CityID").empty();
$("#CityID").html('<option value="">--Select City--</option>');
$.each(data, function (index, row) {
$("#CityID").append("<option value='" + row.CityID + "'>" + row.CityName + "</option>").trigger("chosen:updated")
});
});
})
});
</script>