更新时间:2023-01-17 16:35:18
我做的,以prevent这个错误是返回反映这样我对象的属性一个匿名者键入的内容:
What I'm doing to prevent that error is to return an anonymouse type that reflects my object's properties like this :
public JsonResult CompanyListJson()
{
var list = (from companies in appContext.Companies
where companies.Active.Equals(true)
select new
{
Name = companies.DbName,
Id = companies.Id,
Active = companies.Id.Equals(CurrentCompany.Id)
});
return Json(list, JsonRequestBehavior.AllowGet);
}
也许这是不是***的方式,但它可以让我保持我的JSON薄,只推我需要的数据(并避免当然是循环引用除外)
Maybe it's not the best way, but it allows me to keep my JSON thin and push only the data I need ( and avoid that circular reference exception of course )
在你的样品看,我就从SearchAnalysis选择新的匿名者类型,以我所需要的属性。这应该工作
Looking at your sample, I would select new anonymouse type from SearchAnalysis, taking the properties I need. That should work