I have read a lot about this type of error :
我已经阅读了很多关于这种错误的信息:
"A circular reference was detected while serializing an object of type ..." But I could not found a solution to it when it happens in ASP.Net MVC Kendo Grid Action Method. I have the following action method and I want to insert into another related table at the same time :
“在序列化类型的对象时检测到循环引用......”但是当它在ASP.Net MVC Kendo Grid Action Method中发生时,我找不到解决方案。我有以下操作方法,我想同时插入另一个相关的表:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SeasonTradeCreate([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<BKP_STRADE> models, decimal? DOC_SEQ)
{
if (models.Any())
{
foreach (BKP_STRADE modelItem in models)
{
Db.BKP_STRADE.Add(modelItem);
BKP_STRADE_ROW BKP_STRADE_ROW_OBJ = new BKP_STRADE_ROW();
BKP_STRADE_ROW_OBJ.BSTR_BSTR_SEQ = modelItem.BSTR_SEQ;
BKP_STRADE_ROW_OBJ.DOC_SEQ = DOC_SEQ;
Db.BKP_STRADE_ROW.Add(BKP_STRADE_ROW_OBJ);
}
Db.SaveChanges();
}
return Json(models.ToDataSourceResult(request, ModelState));
}
The thing is that it inserts into both table correctly but I get the following error as well after the operation :
问题是它正确地插入到两个表中但是在操作之后我也得到以下错误:
"A circular reference was detected while serializing an object of type 'Tpph.Models.BKP_STRADE'."
“序列化'Tpph.Models.BKP_STRADE'类型的对象时检测到循环引用。”
1 个解决方案
#1
0
Can you change
你能改变吗?
return Json(models.ToDataSourceResult(request, ModelState));
with this
return Json(new[] { models }.ToDataSourceResult(request, ModelState));
#1
0
Can you change
你能改变吗?
return Json(models.ToDataSourceResult(request, ModelState));
with this
return Json(new[] { models }.ToDataSourceResult(request, ModelState));