【发布时间】:2020-04-27 14:20:54
【问题描述】:
我的 ASP.NET MVC 项目中出现循环引用错误
这是模型
public partial class Item
{
public Item()
{
this.Inventories = new HashSet<Inventory>();
this.PurchasesDetails = new HashSet<PurchasesDetail>();
this.SalesDetails = new HashSet<SalesDetail>();
}
public int Id { get; set; }
public string Code { get; set; }
public int CategoryID { get; set; }
public string Name { get; set; }
public int MeasurementID { get; set; }
public int Quantity { get; set; }
public decimal BuyPrice { get; set; }
public decimal SalePrice { get; set; }
public decimal CommisionRate { get; set; }
public Nullable<System.DateTime> MftDate { get; set; }
public Nullable<System.DateTime> ExpDate { get; set; }
public Nullable<int> StockLimit { get; set; }
public string Description { get; set; }
public string UserID { get; set; }
public virtual AspNetUser AspNetUser { get; set; }
public virtual Category Category { get; set; }
public virtual ICollection<Inventory> Inventories { get; set; }
public virtual Measurement Measurement { get; set; }
public virtual ICollection<PurchasesDetail> PurchasesDetails { get; set; }
public virtual ICollection<SalesDetail> SalesDetails { get; set; }
}
这是获取 JSON 的代码
db.Configuration.ProxyCreationEnabled = false;
var items = db.Items.Include(i => i.AspNetUser).Include(i => i.Category).Include(i => i.Measurement).ToList();
return Json(new { data = items }, JsonRequestBehavior.AllowGet);
我尝试使用db.Configuration.ProxyCreationEnabled = false;,但它不起作用。任何帮助将不胜感激。
【问题讨论】:
标签: c# json asp.net-mvc asp.net-mvc-5