3

I am working on AngularJs with MVC , I am having a silly issue while passing model to MVC controller.

If I Debug the code .. data is there in object till I make ajax post call.. but when I check on controller everything becomes null.

Here is my code

AngularController

$scope.loginUser = { email: "", password: "", typeofUser: "ExternalUser" } var onLoginComplete = function (data) { console.log(data); }; var onError = function (reason) { $scope.error = "Could not fetch the data."; }; DataService.validateUser($scope.loginUser).then(onLoginComplete, onError); 

Now DataService

 var baseurl = window.location.protocol + "//" + window.location.host + "/"; var validateUser = function (model) { return $http.post(baseurl + "Account/Login/" + model) .then(function (response) { return response.data; }); } 

and Model class in MVC

public class LoginViewModel { [Required] [Display(Name = "Email")] public string Email { get; set; } [Required] [StringLength(50, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; } [Required] public string TypeofUser { get; set; } } 

Now you can below image that before making post call to controller , object has values.. enter image description here

But after going to controller , all values are null

enter image description here

1 Answer 1

2

Post parameters are not correct. Replace + with ,.

return $http.post(baseurl + "Account/Login/", model) 

You can read more here.

$http.post('/someUrl', data, config).then(successCallback, errorCallback); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.