Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

model value null when passed from angular post service

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

like image 900
Mahajan344 Avatar asked May 25 '26 07:05

Mahajan344


1 Answers

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);
like image 92
Win Avatar answered May 30 '26 18:05

Win



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!