zoukankan      html  css  js  c++  java
  • 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("");
                }
            
  • 相关阅读:
    通过xshell在本地win主机和远程linux主机传输文件
    CentOS7.4搭建ftp服务
    CentOS7.4中配置jdk环境
    spring AOP学习笔记
    java代码连接oracle数据库的方法
    通过xshell上传和下载文件
    java设计模式简述
    本地项目文件通过git提交到GitHub上
    centos7中oracle数据库安装和卸载
    centos7远程服务器中redis的安装与java连接
  • 原文地址:https://www.cnblogs.com/wangdongying/p/11378723.html
Copyright © 2011-2022 走看看