正是这样,我一定已经从我的 Controller 发送了一些内容到 Angularjs,这些内容将产生诸如仅 L 本身或 E 之类的单词,所以换句话说,只要让这些单词具有单个字母的符号。
控制台没有转发任何错误,我认为问题在于它没有向侧面指定任何值。
我在这里尝试过:
加载.js
var app = angular.module('WordSpreads',[]);
app.controller('WordSpreadsListValue', function ($scope, $http) {
$http(
{
method: 'GET',
url: '../Profile/MWordSpreads'
}).success(function (response) {
$scope.entries = data.List;;
});
console.log("TEST");//It does not appear in the console log.
});
Controller :
[HttpGet]
public JsonResult MWordSpreads()
{
WordsSpreadsListValue model = new WordsSpreadsListValue();
var db = HelperToTables.DbValue;
model.List = db.WordSpreads.ToList();
return Json(model.List, JsonRequestBehavior.AllowGet);
}
型号:
public class WordsSpreadsListValue
{
public List<WordSpread> List { get; set; }
}
错误给我:
A circular reference was detected while serializing an object of type 'xxSitename.Models.LinqDatabase.WordSpread'
更新:
model.List = db.WordSpreads.Select(x => new {
Name = x.name,
TextValue = x.text.ToString()
}).ToList();
错误:
Cannot implicitly convert type 'System.Collections.Generic.List<>' to 'System.Collections.Generic.List' MVCOrdklar2015
.
最佳答案
model.List = db.WordSpreads.Select(x => new { Prop1 = x.1, Prop2 = x.2}).ToList();
您在序列化 model.List
时遇到问题,Json 序列化在序列化 model.List 时出现问题。如果你把它变成一个没有导航属性的新对象,那就没问题了。
根据我的经验,它与导航属性有关,我不完全理解它是什么。但是,一旦您从等式中删除导航属性,它就会起作用。
关于javascript - 将列表返回到 JSON 到 Angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38402223/