Entity to json error - A circular reference was detected while serializing an object of type

前端 未结 5 981
醉梦人生
醉梦人生 2021-01-02 02:22

Following error occurred when trying to convert entity object into JSON String. I\'m using C# MVC4 with code first DB designing. It seams its because FKs and relationships b

5条回答
  •  时光说笑
    2021-01-02 02:34

    I was having the same issue, what I have done is have passed only needed column to view , In my my case. only 2.

    List lstSubCategory = GetSubCateroy() // list from repo
    
     var subCategoryToReturn = lstSubCategory.Select(S => new { Id  = S.Id, Name = S.Name }); 
    
    return this.Json(subCategoryToReturn , JsonRequestBehavior.AllowGet);
    

    Circular reference detected exception while serializing object to JSON

提交回复
热议问题