请求有效负载中显示的数据不在控制器

时间:2017-11-08 11:56:27

标签: c# angularjs asp.net-mvc

我通过文本字段中的JSON字符串传递信息。这是每个问题的一个答案,多个客户回答同一个问题。我遇到的问题是信息被传递到网络控制台中的请求有效负载。但是,我没有在C#控制器类的列表中看到它。

request payload

以下是控制器中列表的调试,其中SysIntClients列表未流经。然而,它来自网络响应中的有效载荷:

Controller class

我的ng-repeat看起来如下:

<div class="row" ng-repeat="question in Question" ng-if="question.SI_ID == '1'">
        <div class="col-lg-6">
        <label class="labelQuestion" id="question_label" for="question_answer">{{question.QID}}: {{question.Question1}}</label>
        </div>
              <div class="row">
              <div class="col-lg-6">
             <input type="{{question.input_type}}" ng-model="question.SysIntClients.Answer" class="form-control" ng-style="{'height': question.input_type == 'radio' ? '20px' : '40px'}" name="question_answer" id="question_answer" required        {{question.SysIntClients.Answer}}
          </div>
      </div>
   </div>

我的角度代码如下:

$scope.SysIntClients =
            [{
                Answer: ''
            }]

            $scope.Question = [{
                QID: '',
                SI_ID: '',
                Question1: '',
                input_type: '',
                SysIntClients: [{
                    Answer: ''
                }]
            }]

 var array = [];
 array = $scope.Question;

                                    alert("Thank you for your input. Now saving data.");
                                    //Save Data
                                    //$scope.sendForm = function (Courier, Customer, Integration, intCapabilities, Retailer) {
                                    $log.log("in the save data function");

                                    $log.log("Form is valid");

                                    //$scope.Courier = Courier; // in order to pass to the reg service in var data
                                    //$scope.Customer = Customer;
                                    //$scope.Integration = Integration;
                                    //$scope.intCapabilities = intCapabilities;
                                    //$scope.Retailer = Retailer;

                                    //var submitData = registrationService.SaveFormData($scope.Courier, $scope.Customer, $scope.Integration, $scope.intCapabilities, $scope.Retailer);

                                    $log.log("in registration service");

                                    //var fac = {};
                                    //fac.SaveFormData = function (Courier, Customer, Integration, intCapabilities, Retailer) {

                                    $log.log("array: " + array);
                                    $log.log("array length: " + array.length);
                                    $log.log("Question: " + $scope.Question);

                                    $log.log("in fac.SaveFormData");

                                    var defer = $q.defer();
                                    var postToAction = $http({
                                        url: '/Home/RegisterUser',
                                        method: 'POST',
                                        data: JSON.stringify({ 'Courier': $scope.Courier, 'Customer': $scope.Customer, 'Station': $scope.Station, 'Integration': $scope.Integration, 'intCapabilities': $scope.intCapabilities, 'Question': array }),
                                        headers: { 'content-type': 'application/json' }
                                    });

任何人都知道为什么我的SysIntClient.Answer变量没有通过?

1 个答案:

答案 0 :(得分:0)

MVC希望SysIntClients成为客户端的数组。看起来你的设置是正确的,从我能说的是什么?在服务器上,MVC允许您访问进来的原始请求,因此我建议您检查发送到服务器的原始数据,看看是否格式不正确。