使用来自mvc控制器的json的角度加载选择列表

时间:2015-09-28 13:00:02

标签: javascript json angularjs asp.net-mvc

以下是我的观点:

  <div>
     <select ng-model="firstSupplier" ng-options="firstSupplier as firstSupplier.SupplierName for firstSupplier in jsonSuppliers"></select>
  </div>

这是我的角度控制器:

(function(){     var app = angular.module(&#34; CustCMS&#34;);

var indexController = function($scope, $http) {
    $http.get("/Home/GetAllSuppliers")
                                .then(function (response) {
                                    $scope.jsonSuppliers = response.data;
                                    $scope.firstSupplier = $scope.jsonSuppliers[0];
                                });




};

app.controller("IndexController", ["$scope", "$http", indexController]);

}());

这是我的mvc控制器:

   public JsonResult GetAllSuppliers()
    {
        var suppliers = GetAll();
        return Json(new { data = suppliers}, JsonRequestBehavior.AllowGet);
    }

这里是返回角度控制器jsonSuppliers的json:

    {"data":[{"SupplierId":1,"SupplierName":"Normstahl","PrefixCountryCode":"NS01COUNTRY","UseOrderSystem":false,"IsDirect":false,"Customers":[]},{"SupplierId":2,"SupplierName":"TestSupplier 2","PrefixCountryCode":null,"UseOrderSystem":false,"IsDirect":false,"Customers":[]},{"SupplierId":3,"SupplierName":"Ditec","PrefixCountryCode":"DIIT01COUNTRY","UseOrderSystem":false,"IsDirect":false,"Customers":[]},{"SupplierId":4,"SupplierName":"Ospf","PrefixCountryCode":"CRCOUNTRY","UseOrderSystem":false,"IsDirect":false,"Customers":[]},{"SupplierId":5,"SupplierName":"Alsta","PrefixCountryCode":null,"UseOrderSystem":false,"IsDirect":false,"Customers":[]}]}

这里遗失的是什么? 我在控制台中没有收到任何错误.... 是否有一种更容易的方法,非常感谢!

0 个答案:

没有答案