小编Dla*_*h14的帖子

为什么我的JSON响应被返回用方括号[]包围?

我试图找出为什么我的JSON响应被方括号包围.我正在使用ASP.NET Web API和Angular.我认为这就是我的Angular代码没有打印到HTML的原因.

namespace GeekQuiz.Controllers
{
    public class TrialController : ApiController
    {
        private TriviaContext db = new TriviaContext();

        // GET api/trial
        public IQueryable<TriviaQuestion> GetTriviaQuestions()
        {
            return db.TriviaQuestions;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码来自我的 TrialController,我正在接受Angular的调用.

var app = angular.module('myApp', []);
app.controller('questCtrl', function ($scope, $http) {
    $http.get("/api/trial").success(function (data, status, headers, config) {
        $scope.options = data.options;
    }).error(function (data, status, headers, config) {
        $scope.title = "Oops... something went wrong";
        $scope.working = false;
    });
});
Run Code Online (Sandbox Code Playgroud)

这是我的浏览页面:

@{
    ViewBag.Title = "Contact";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>

<div ng-app="myApp" ng-controller="questCtrl"> …
Run Code Online (Sandbox Code Playgroud)

javascript c# asp.net json angularjs

1
推荐指数
1
解决办法
1424
查看次数

标签 统计

angularjs ×1

asp.net ×1

c# ×1

javascript ×1

json ×1