【问题标题】:Stuck with Angularjs坚持使用 Angularjs
【发布时间】:2013-10-30 16:32:30
【问题描述】:

您好,我是 angularjs 新手,我正在使用 visualstudio 2012 mvc4 创建一个 Angularjs 应用程序,我需要一些帮助来处理请求。

这是我的get方法

    // 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

【问题讨论】:

  • 跳转代码并没有改变任何东西,我仍然得到了和以前一样的结果。

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


【解决方案1】:

返回 JSON。

public JsonResult Index()
{
    var cards = ml.getSortedDeck(); 
    return Json(cards, JsonRequestBehavior.AllowGet);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-09
    • 2014-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多