在序列化“SubSonic.Schema .DatabaseColumn”类型的对象时检测到循环引用。 [英] A circular reference was detected while serializing an object of type 'SubSonic.Schema .DatabaseColumn'.
问题描述
public JsonResult GetEventData ()
{
var data = Event.Find(x => x.ID!= 0);
return Json(data);
}
我收到一个HTTP 500,例外情况如此题目所示。我也试过
var data = Event.All()。ToList()
同样的问题。
这是一个错误还是我的实现? >
似乎在对象层次结构中有一些循环引用,它不受JSON序列化程序的支持。你需要所有的列吗?您可以在视图中只接收您需要的属性:
return Json(new
{
PropertyINeed1 = data.PropertyINeed1,
PropertyINeed2 = data.PropertyINeed2
});
这将使您的JSON对象更轻更易于理解。如果您有许多属性,则 AutoMapper 可用于映射DTO对象和View对象之间的.com / blogs / jimmy_bogard / archive / 2009/06/29 / how-we-do-mvc-view-models.aspx。 p> I am trying to do a simple JSON return but I am having issues I have the following below. I get a HTTP 500 with the exception as shown in the title of this question. I also tried That gave the same problem. Is this a bug or my implementation? It seems that there are circular references in your object hierarchy which is not supported by the JSON serializer. Do you need all the columns? You could pick up only the properties you need in the view: This will make your JSON object lighter and easier to understand. If you have many properties, AutoMapper could be used to automatically map between DTO objects and View objects. 这篇关于在序列化“SubSonic.Schema .DatabaseColumn”类型的对象时检测到循环引用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!public JsonResult GetEventData()
{
var data = Event.Find(x => x.ID != 0);
return Json(data);
}
var data = Event.All().ToList()
return Json(new
{
PropertyINeed1 = data.PropertyINeed1,
PropertyINeed2 = data.PropertyINeed2
});