boycoto

boycoto

  • NA
  • 147
  • 125.5k

[ASP.NET Core+AngularJS] Controller gets NULL value

Jan 13 2017 2:14 AM
I am using VS2015. I am getting error in my controller class (System.NullReferenceException) but in my angularjs I get the value 
  1. {"UserName":"admin","UserPassword":"password"}  
Hoping you can help me on this. Thanks in Advance. 
 
Below is my controller class:
 
  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.     $scope.LoginCheck = function () {  
  3.   
  4.         $scope.userlogin = {  
  5.             UserName: $scope.usrName,  
  6.             UserPassword: $scope.usrPassword  
  7.         }  

  8.         var getData = CartExpressService.UserLogin($scope.UserAccessViewModel);  
  9.         getData.then(function (d) {  
  10.             $scope.msg = d.data;  
  11.             alert($scope.msg);  
  12.  
  13.         });  
  14.         debugger;  
  15.     }  
  16.   
  17.   
  18. });  
 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. });  
Views
  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>  
  17.   
  18. form>  
 
 Error:
 
 
 
 
 
 

Answers (1)