您好,我是 angularjs 新手,我正在使用 Visualstudio 2012 mvc4 创建 Angularjs 应用程序,我需要一些请求方面的帮助。
这是我的获取方法
// GET: /getCard/
Logic l = new Logic();
public List<Cards> Index()
{
var cards = ml.getSortedDeck();
return cards;
}
这是我的js代码
MemoryApp.factory('Cards', function($resource){
return $resource('/getCard/', { method: 'GET', isArray: true });
});
var ColourCtrl = function ($scope, Cards, $routeParams, $resource) {
$scope.cards = [];
$scope.setcards = function () {
Cards.query(function (data) {
console.log(data);
$scope.cards = $scope.cards.concat(data);
});
}
$scope.setcards();
}
当我单步执行我的后端代码时,它工作得很好,我在“卡片”列表中得到了 16 个点击,这是正确的数量。尽管当我在网站上检查 console.log 时,我有一个包含 59 个项目的数组,这些项目对我来说无法使用。
当我检查网络选项卡下的响应部分时,我收到此消息 “System.Collections.Generic.List`1[Memory.Models.Cards]”,这对我来说似乎是正确的。
最诚挚的问候/M
最佳答案
返回 JSON。
public JsonResult Index()
{
var cards = ml.getSortedDeck();
return Json(cards, JsonRequestBehavior.AllowGet);
}
关于c# - 被 Angularjs 困住了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19688601/