如何使用jQuery通过DropdownList传递两个或多个参数?

如何使用jQuery通过DropdownList传递两个或多个参数?,jquery,asp.net,json,asp.net-mvc-5,Jquery,Asp.net,Json,Asp.net Mvc 5,HomeController 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 = cit

HomeController

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);
}
查看

@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>

建议您在中学习代码-尽管您可能认为您的代码不能100%工作。(代码存在多个问题-请尝试返回视图开始)。您只需
CityID
即可获取相关的
郊区
,因此不清楚您为什么要发送
地区ID
。问题是我的数据库没有将郊区链接到城市。它们通过地区连接。城市属于一个地区,郊区也属于一个地区(两个表中的DistrictID都是外键)。一个地区属于一个省/州。一旦获得,城市就不会通过一个省连接起来。这是数据库的配置方式,因此我对城市和郊区之间的关系有问题。然后你应该修复你的数据库我的数据库已经有数据和关系了,几乎不可能进行任何修改。然后只需执行
$.get(“/Home/get郊区”,{DistrictID:$(“#DistrictID”).val()
public JsonResult GetSuburb(string DistrictID,int CityID)
{
    ...................
    return Json(ViewBag.Suburb, JsonRequestBehavior.AllowGet);
}