从角度邮政服务

时间:2016-06-02 22:26:56

标签: angularjs asp.net-mvc

我正在使用MVC处理AngularJs,在将模型传递给MVC控制器时遇到了一个愚蠢的问题。

如果我调试代码..数据在对象中,直到我调用ajax ...但是当我检查控制器时,一切都变为空。

这是我的代码

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);

现在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;
                                });
            }

和MVC中的Model类

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; }
    }

现在你可以在下面的图像中,在对控制器进行调用之前,对象有值.. enter image description here

但是在转到控制器后,所有值都为空

enter image description here

1 个答案:

答案 0 :(得分:2)

发布参数不正确。将+替换为,

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

您可以阅读更多here

$http.post('/someUrl', data, config).then(successCallback, errorCallback);