I am using VS2015. I am getting error in my controller class (System.NullReferenceException) but in my angularjs I get the value
- {"UserName":"admin","UserPassword":"password"}
Hoping you can help me on this. Thanks in Advance.
Below is my controller class:
- [HttpPost]
- public JsonResult AuthenticateUser(UserAccessViewModel _users)
- {
-
- var users = _context.UserAccess.Where(w => w.Username.Equals(_users.UserName) && w.Userpassword.Equals(_users.UserPassword));
-
- return Json(users);
- }
Controller.js
- app.controller("MyController", function ($scope, MyService) {
- $scope.LoginCheck = function () {
-
- $scope.userlogin = {
- UserName: $scope.usrName,
- UserPassword: $scope.usrPassword
- }
- var getData = CartExpressService.UserLogin($scope.UserAccessViewModel);
- getData.then(function (d) {
- $scope.msg = d.data;
- alert($scope.msg);
-
- });
- debugger;
- }
-
-
- });
Service.js
- app.service("MyService", function ($http) {
-
- this.UserLogin = function (user) {
-
- var response = $http({
- method: "post",
- url: "../Administrator/AuthenticateUser",
- data: JSON.stringify(user),
- dataType: "json"
- });
-
- return response;
- }
- });
Views
- <div style="margin-bottom: 25px" class="input-group">
- <span class="input-group-addon"><i class="glyphicon glyphicon-user">i>span>
- <input type="text" class="form-control" ng-model="UserAccessViewModel.UserName" placeholder="Username">
- div>
-
- <div style="margin-bottom: 25px" class="input-group">
- <span class="input-group-addon"><i class="glyphicon glyphicon-lock">i>span>
- <input type="password" class="form-control" ng-model="UserAccessViewModel.UserPassword" placeholder="Password">
- div>
-
- <div style="margin-top:10px" class="form-group">
-
- <div class="col-sm-12 controls">
- <a id="btn-login" href="#" class="btn btn-success" ng-click="LoginCheck()">Login a>
- div>
- div>
-
- form>
Error: