c# - 被 Angularjs 困住了

标签 c# javascript asp.net-mvc asp.net-mvc-4 angularjs

您好,我是 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/

相关文章:

c# - 从方法返回内存流

javascript - 如何从文件中获取纯xml

asp.net-mvc - 自定义 View 引擎中的 ASP.NET MVC 自定义属性

c# - 如何在与 ItemsSource 绑定(bind)的 ListBox 中显示子元素的属性?

c# - 我可以使用 LINQ 比较两个数组中的范围吗?

javascript - 如果启用了 Javascript,则将提交按钮替换为 onclick 事件

c# - Entity Framework /Azure Web服务模型设计

asp.net-mvc - 模型未在 POST 上正确提交/绑定(bind)

c# - 我什么时候应该使用 WaitHandle 而不是锁

javascript - 浏览器周围 Javascript 中的实例评估