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 :
[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'."