zoukankan      html  css  js  c++  java
  • 级联变动

    public JsonResult getDepartmentJson(int CompanyId = 0)
            {
                List<SelectListItem> SelectItems = new List<SelectListItem>();

                IEnumerable<Department> SerieslistsJieGuo = db.department.Where(o => o.CompanyId == CompanyId).ToList();
                foreach (Department br in SerieslistsJieGuo)
                {
                    SelectItems.Add(new SelectListItem { Text = br.DepartmentName, Value = br.Id.ToString() });
                }

                return Json(SelectItems, JsonRequestBehavior.AllowGet);
            }

      //查询出所有公司
                ViewBag.Company = new SelectList(db.company.OrderBy(o=>o.Id),"Id","CompanyName");
                //默认显示Id排序第一个公司的部门
                int firstCompanyId = db.company.OrderBy(o => o.Id).FirstOrDefault().Id;
                ViewBag.Department = new SelectList(db.department.Where(o=>o.CompanyId==firstCompanyId), "Id", "DepartmentName");

    //前台页面

    <script language="javascript" type="text/javascript">

        $(document).ready(function () {
            $("#Company").change(function () { getSeriesSelectList() });
        });

        function getSeriesSelectList() {
            $("#Department").empty();
            if ($("#Company").val() != "") {
                var url = "/Home/getDepartmentJson?CompanyId=" + $("#Company").val();
                $.getJSON(url, function (data) {
                    $.each(data, function (i, item) {
                        $("<option></option>").val(item["Value"]).text(item["Text"]).appendTo("#Department");
                    });
                });
            }
        }
    </script>
    @Html.DropDownList("Company")
    @Html.DropDownList("Department")

  • 相关阅读:
    仅坚持了9天:京东今日宣布暂停火车票代购业务
    Highcharts JS——制作图表的纯js类库
    eclipse插件——php工具集成
    如何新增histats计数器到自己的 blog
    C#写入文本txt
    我怎么感觉js快无敌了~
    马云卸任演讲全文
    添加好玩的honehoneclock到自己的blog
    C#获取日期的年月日时分秒
    js闭包
  • 原文地址:https://www.cnblogs.com/heifengwll/p/3473292.html
Copyright © 2011-2022 走看看