AngularJS:隐藏ID不在控制器中发送

时间:2016-02-26 03:07:48

标签: angularjs asp.net-mvc-4

我的想法是,当我点击该帐户时,会弹出一个模态,系统菜单将显示在下拉列表中。我的问题是帐户的ID,当我在控制器中发送它时,我在表单中作为隐藏类型没有任何值。

这是我的表格:

<form novalidate name="addMenusforuser" ng-submit="addMenuData(addMenusforuser)">
        <table>
            <tr>
                <input type="hidden" name="account_info_id" ng-model="masterlist.account_info_id" value="masterlist.account_info_id">
                <th>
                    System Menus 
                </th>
                <td>
                    <select class="form-control" ng-model="masterlist.system_menus_id" ng-options="c.system_menus_id as c.sm_description for c in menus" required></select>
                </td>
            </tr>
        </table>
    <button type="submit" class="btn btn-primary" id="addbtn">Add</button>
</form>

我的AngularJS:

/**Add Menu to database*/
    $scope.addMenuData = function (form) {
        if (!form.$valid) {
            alert("fill-up everything.");
            return false;
        }
        var formData = [];
        for (index in $scope.masterlist) {
            formData.push({ "name": index, "value": $scope.masterlist[index] });
        }
        $http.post('/Accounts/AddMenusForUser', $.param(formData)).then(function (response) {
            if (form) {
                form.$setPristine();
                form.$setUntouched();
            }
            angular.element("#addMenu").modal("hide");
            $scope.display();
        });
    }

这是我的MVC控制器,其中account_info_id为null:

        public ActionResult AddMenusForUser(int system_menus_id = 0, int account_info_id = 0)
        {
            var check = db.System_Menu_Roles.Where(x => x.system_menus_id == system_menus_id && x.account_info_id == account_info_id).FirstOrDefault();
            if (check == null)
            {
                System_Menu_Roles smr = new System_Menu_Roles();
                smr.account_info_id = account_info_id;
                smr.system_menus_id = system_menus_id;
                smr.active_flag = true;
                db.System_Menu_Roles.Add(smr);
                db.SaveChanges();
            }

            return null;
        }

有人可以给我建议我将如何解决这个问题?提前谢谢。

1 个答案:

答案 0 :(得分:0)

检查您是否提交功能参数 它应该是

<form novalidate name="addMenusforuser" ng-submit="addMenuData(masterlist)">

并且在功能

$scope.addMenuData = function (form) {
 alert (JSON.stringify(form));