我试图搜索但无法解决我的问题。
这是我的控制器:
public JsonResult Index()
{
return this.Json(TempData["displayList"], JsonRequestBehavior.AllowGet);
}
public JsonResult AddToCart(string id)
{
QuotationModels objQuote = new QuotationModels();
List<QuotationModels> listQuote = objQuote.GetObjectInSession;
int itemID = Int32.Parse(id);
int index = -1;
if(listQuote != null)
index = listQuote.FindIndex(p => p.ItemdID== itemID);
if (index >= 0)
{
listQuote[index].ProductQty++;
objQuote.AddToSession(listQuote);
}
else
{
int _id = Convert.ToInt16(id);
var _product = DataContext.DataContext.Items.FirstOrDefault(s => s.ID == _id);
QuotationModels quote = new QuotationModels();
quote.ItemdID = _product.ID;
quote.ItemNote = _product.Notes;
quote.Phone = "";
quote.PictureName = _product.PictureName;
quote.ProductName = _product.Name;
quote.ProductPrice = (decimal)_product.Price;
quote.ProductQty = 1;
quote.ShoppingCartId = "";
quote.Total = 0;
quote.Email = "";
quote.CustomerID = 0;
quote.CusName = "";
quote.Company = "";
quote.Address = "";
objQuote.AddToSession(quote);
}
int itemInSession = objQuote.GetObjectInSession.Sum(s => s.ProductQty);
TempData["displayList"] = objQuote.GetObjectInSession;
return Json(new
{
ja = itemInSession
}, JsonRequestBehavior.AllowGet);
}
但是当我浏览 Index() 视图时,这是一个错误A circular reference was detected while serializing an object of type
。
任何人都可以给我解决方案。太感谢了。