asp.net发布请求表单为空

时间:2017-12-08 19:15:38

标签: c# asp.net angularjs asp.net-mvc

我正在使用angularJS + asp.net进行发布请求,但Request.Form始终为空。这是我的代码

Index.cshtml

<v-mycoolform :slug="{{$lesson->subject->slug}}" :token="{{csrf_token()}}" :tags="{{json_encode($tags)}}"/>

HomeController.cs

<div ng-app="phone" ng-controller="phoneCtrl">
    <input type="text" ng-model="phoneNumber">
    <button ng-click="sendSMS()"> Submit </button>
    <br>
    {{response}}
    {{error}}
</div>

@section scripts {
    <script>
        var app = angular.module('phone', []);
        app.controller('phoneCtrl', function ($scope, $http) {
            $scope.sendSMS = function () {
                var params = {
                    phone : $scope.phoneNumber
                };

                var config = {
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
                    }
                };

                $http.post('Home/sendSMS',params , config)
                .then(function (response, status, headers, config) {
                    $scope.response = response.data;
                })
                .catch(function (data, status, headers, config) {
                    $scope.error = data;
                });
            };
        });
    </script>
}

Request.Form总是为空但我可以在帖子请求的请求正文中看到一个电话条目,所以我想知道我是否在.net

中提取错误的数据

1 个答案:

答案 0 :(得分:0)

您是否尝试将Content-Type更改为Json。

            var config = {
                headers: {
                    'Content-Type': 'application/json;'
                }
            };