• MVC DropDownLis 二级联动实现


    二级联动:
    View: 
    <script type="text/javascript">    
        $(function () {       
            $("#drpProvince").change(function () { 
                $("#drpCity").get(0).options.length = 0; //清空
                $.getJSON("/Persons/GetCities/" + $(this).val(), null , function (data) {
                    $.each(data, function (i, item) {
                        $("<option></option>").val(item["ID"]).text(item["CityName"]).appendTo($("#drpCity"));
                    });
                });
            });
        });
    </script>
     
    @Html.DropDownList("drpProvince",null,"请选择")
    @Html.DropDownList("drpCity"null,"请选择")
     
    Action:
     
              public ActionResult Create()
            
                List<Provinces> list = db.Provices.ToList();
                ViewData["drpProvince"] = new SelectList(list, "ID""ProvinceName");
                ViewData["drpCity"] = new List<SelectListItem>();
                return View();
            }
     
            //返回城市列表
            public ActionResult GetCities(int? id)
            {
                List<Cities> list = db.Cities.Where(q => q.ProvincesID == id).ToList();
                if (Request.IsAjaxRequest())
                {
                    return Json(list, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return View("");
                }
            
  • 相关阅读:
    IOC和DI的区别
    hdu 1217(Floyed)
    hdu 2112(字典树+最短路)
    hdu 4081(次小生成树)
    hdu 1811(缩点+拓扑排序+并查集)
    poj 3026(BFS+最小生成树)
    hdu 3635(并查集)
    hdu 3047(扩展并查集)
    hdu 1116(并查集+欧拉路径)
    poj 1679(次小生成树)
  • 原文地址:https://www.cnblogs.com/wangdongying/p/11378723.html
Copyright © 2020-2023  润新知