TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
boycoto
NA
147
125.5k
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.
{"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.
Reply
Answers (
1
)
Login and Logout in ASP.NET MVC
how to use checkbox in datalist without select btn