2016-11-04 10 views
0

私はASP.NET MVCウェブサイトのデータバインディングにAngularJSを使用しています。以下に示すように私を見るには、私は角のコントローラを持っている:AnguarJSを使用してリストが表示されない

<script>   
    function questionController($scope, $http, questions) {  
     $scope.queList = $http.get('Question/GetAllQuestions'); 
     $scope.testList = ['a','b']; 
    } 
    var queApp = angular.module("queApp", []); 
    queApp.controller("queCtrl", questionController); 
<script> 

の下に与えられたとして、私は、データを表示しています:

<div ng-app="queApp"> 
    <div ng-controller="queCtrl"> 
     {{queList}} 
     {{testList}} 
     <div ng-repeat="question in queList"> 
      {{question.Body}} 
     </div> 
    </div> 
</div> 

アクションメソッドのコードは以下のとおりである:

public JsonResult GetAllQuestions() 
{ 
    Questions questions; 
    QuestionProvider quePro = new QuestionProvider(); 
    questions = quePro.GetQuestions(); 
    return Json(questions); 
} 

私はMVCコントローラコードをデバッグして、リクエストがアクションメソッドに当たっていて、質問のリストが返されていることがわかりましたが、ビューに というリストが表示されません。ただし、testListが表示されます。もし私が何かを欠けているなら、私に知らせてください。

+0

$ http.get約束を返します。 – garethb

答えて

1

これが好きですか、コントローラのアクションメソッド内

$http.get('Question/GetAllQuestions').then(function (response){ 
       $scope.queList = response.data; 
       console.log(data) 
    }); 
0

JsonRequestBehavior.AllowGetは、下記のようにそれが仕事作っ:

return Json(questions, JsonRequestBehavior.AllowGet); 
関連する問題