asp.net mvc 4 - AngularJS: Hidden ID not send in the controller -
the idea when clicked account, modal pop-up , system menus in dropdownlist. problem id account made hidden type in form have no value when send in controller.
here form:
<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 c.sm_description c in menus" required></select> </td> </tr> </table> <button type="submit" class="btn btn-primary" id="addbtn">add</button> </form>
my angularjs:
/**add menu database*/ $scope.addmenudata = function (form) { if (!form.$valid) { alert("fill-up everything."); return false; } var formdata = []; (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(); }); }
and here mvc controller 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; }
can give me advice how solve one? in advance.
check submit function parameter should
<form novalidate name="addmenusforuser" ng-submit="addmenudata(masterlist)">
and in function
$scope.addmenudata = function (form) { alert (json.stringify(form));
Comments
Post a Comment