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.
- {"UserName":"admin","UserPassword":"password"}
Below is the code of my class controller.
- [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;
- }
- });
Index.cshtml
- <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>
I do not know what is wrong with my code. Hope you can help me on this. Thanks in advance.