【问题标题】:cascading dropdown angularjs mvc级联下拉angularjs mvc
【发布时间】:2018-07-21 02:28:56
【问题描述】:

我得到空值

 $scope.GetDepartment = function (Department) {
        $http.get('/Official/GetDepartment?Department=' + Department).then(function (data) {
            console.log(data);
            $scope.department= data.data;
        });
    };

HTML

  <select ng-model="empModel.division" id="" name="Division" class="form-control"   
                                ng-click = "GetDepartment(empModel.division)"  
                                ng-change = "GetDepartment(empModel.division)"
                                ng-options="c.division as c.division for c in division" >
                            <option selected="selected">Select</option>
                        </select>

 <select ng-model="empModel.department" id="" name="Department" class="form-control"
                                    ng-options="d.department as d.department for d in department">
                                <option></option>
                            </select>

当我选择部门时,部门下拉列表中没有任何内容 控制器

  public JsonResult GetDepartment(string Department)
    {
        var department = db.Depts.Where(x => x.Department == Department).
            GroupBy(x => x.Department).
            Select(x => x.FirstOrDefault()).
            OrderBy(x => x.Department).ToList();

        return Json(department);
    }

【问题讨论】:

    标签: asp.net angularjs model-view-controller .net-core


    【解决方案1】:

    您用于检索除法数据的角度部分

        function GetDesignation(input) {
            $http.get('/Official/GetDesignation?designation='+input).then(function (data) {
                console.log(data);
                $scope.designation = data.data;
            });
    
        };
    

    使用 ng-change 指令更改 HTML

      <select ng-model="empModel.division" id="" name="Division" class="form-control" ng-change = "GetDesignation(empModel.division)"
                                        ng-options="c.division as c.division for c in division" >
                                    <option></option>
                                </select>
    

    用于在下拉列表中加载指定数据的新 HTML 标记

      <select ng-model="empModel.designation" id="" name="Designation" class="form-control" 
                                        ng-options="c.designation as c.designation for c in designation" >
                                    <option></option>
                                </select>
    

    【讨论】:

    • 将html代码指定为什么?和除法一样吗?
    • 是的,实际上几乎相同。您必须绑定该变量名称而不是除法,即此处的差异。
    • 我刚刚添加了您提供给我的代码,但它仍然无法正常工作,我发现当我更改部门时它没有调用我的控制器 /Official/GetDesignation ??
    • 如果这个答案对您有用,它能否获得接受和投票,以便其他人也可以使用它?
    • 完美,如果我有任何其他问题,我会发布新的,非常感谢
    猜你喜欢
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 2018-04-25
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2021-03-04
    相关资源
    最近更新 更多