boycoto

boycoto

  • NA
  • 147
  • 123.7k

Controller gets null value

Jan 15 2017 3:44 AM
I am developing a web app using [VS2015] ASP.NET Core and installed AngularJS. My AngularJS works properly. I created three scripts; Module, Service and Controller.  However, I a bit disappointed because, the controller class gets a null value, though as I check in my browser, I got the value inputted by the user.
  1. {"UserName":"admin","UserPassword":"password"}   
 
 Below is the code of my class controller.
 
  1. [HttpPost]      
  2. public JsonResult AuthenticateUser(UserAccessViewModel _users)      
  3. {      
  4.                  
  5.      var users = _context.UserAccess.Where(w => w.Username.Equals(_users.UserName)                && w.Userpassword.Equals(_users.UserPassword));      
  6.                  
  7.      return Json(users);      
  8. }      
 Controller.js
 
  1. app.controller("MyController"function ($scope, MyService) {    
  2.   
  3.     $scope.LoginCheck = function () {    
  4.     
  5.         $scope.userlogin = {    
  6.             UserName: $scope.usrName,    
  7.             UserPassword: $scope.usrPassword    
  8.         }    
  9.   
  10.         var getData = CartExpressService.UserLogin($scope.UserAccessViewModel);    
  11.         getData.then(function (d) {    
  12.             $scope.msg = d.data;    
  13.             alert($scope.msg);    
  14.    
  15.         });    
  16.         debugger;    
  17.     }    
  18.     
  19.     
  20. });    
 
Service.js
  1. app.service("MyService"function ($http) {    
  2.     
  3.     this.UserLogin = function (user) {    
  4.     
  5.         var response = $http({    
  6.             method: "post",    
  7.             url: "../Administrator/AuthenticateUser",    
  8.             data: JSON.stringify(user),    
  9.             dataType: "json"    
  10.         });    
  11.     
  12.         return response;    
  13.     }    
  14. });    
Index.cshtml
  1. <div style="margin-bottom: 25px" class="input-group">    
  2.     <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>    
  3.     <input type="text" class="form-control" ng-model="UserAccessViewModel.UserName" placeholder="Username">    
  4. </div>    
  5.   
  6. <div style="margin-bottom: 25px" class="input-group">    
  7.     <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>    
  8.     <input type="password" class="form-control" ng-model="UserAccessViewModel.UserPassword"  placeholder="Password">    
  9. </div>    
  10.   
  11. <div style="margin-top:10px" class="form-group">    
  12.         
  13.     <div class="col-sm-12 controls">    
  14.         <a id="btn-login" href="#" class="btn btn-success" ng-click="LoginCheck()">Login  </a>    
  15.     </div>    
  16. </div>   
I do not know what is wrong with my code. Hope you can help me on this. Thanks in advance. 
 
 
 
 
 
 
 
 
 
 

Answers (1)