This is a migrated thread and some comments may be shown as answers.

Issue with cyclical references

1 Answer 98 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Masoud
Top achievements
Rank 1
Masoud asked on 03 Jul 2013, 05:10 PM
Hello,

I am using Kendo 2013.1.514.340 with asp.net mvc.

I am sending the Json to the grid that is generated from the following data structure:
I have two entities, Parent and Child.  A Parent can have n Children.  In this case a single Parent has two Children.  

I use NewtonSoft to serialize the Json with the following settings:

SerializerSettings = new JsonSerializerSettings
{
    ContractResolver = new DefaultContractResolver
    {
        IgnoreSerializableAttribute = true,
        IgnoreSerializableInterface = true
    },
    PreserveReferencesHandling = PreserveReferencesHandling.Objects,
    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
When I have the case of a single parent with a single child all works fine.

The following Json is generated for a single parent that has two children:

{
  "$id": "1",
  "Data": [
    {
      "$id": "2",
      "Aktiv": false,
      "AktualisiertAm": "2013-05-16T11:05:20.273",
      "AktualisiertVon": "abascore",
      "Bemerkung": "",
      "Bezeichnung": "Child",
      "ErzeugtAm": "2013-05-16T11:05:20.273",
      "ErzeugtVon": "abascore",
      "Id": "615cba40-7c17-4a98-9371-443310947b81",
      "ParentId": "c6113c45-bd23-44d3-bfa2-470f647adc75",
      "Nr": 1,
      "Rowverion": "AAAAAAAAorQ=",
      "Sprache": "de-de",
      "Status": 0,
      "Parent": {
        "$id": "3",
        "Branche": "",
        "MaAnzahl": 2,
        "PoG": 1,
        "UnternehmenGroesse": 0,
        "Child": [
          {
            "$ref": "2"
          },
          {
            "$id": "4",
            "Aktiv": false,
            "AktualisiertAm": "2013-07-03T18:31:00.953",
            "AktualisiertVon": "abascore",
            "Bemerkung": "",
            "Bezeichnung": "Child2",
            "ErzeugtAm": "2013-07-03T18:31:00.953",
            "ErzeugtVon": "abascore",
            "Id": "6662074d-2682-4c2d-a4fc-c01ae9eb7cfc",
            "ParentId": "c6113c45-bd23-44d3-bfa2-470f647adc75",
            "Nr": 2,
            "Rowverion": "AAAAAAACOlE=",
            "Sprache": "de-de",
            "Status": 0,
            "Parent": {
              "$ref": "3"
            }
          }
        ],
        "AktualisiertAm": "2013-05-16T11:05:05.333",
        "AktualisiertVon": "abascore",
        "Bemerkung": "",
        "Bezeichnung": "Parent",
        "Descriminator": "MAND",
        "Email": "Parent@masdnad.asda",
        "ErzeugtAm": "2013-05-16T11:05:05.333",
        "ErzeugtVon": "abascore",
        "Id": "c6113c45-bd23-44d3-bfa2-470f647adc75",
        "Logo": "",
        "Mobil": "",
        "Name0": "Parent",
        "Name1": "",
        "Nr": 1,
        "Ort": "München",
        "Plz": "12345",
        "Postfach": "",
        "Rowverion": "AAAAAAAAorI=",
        "SatzQuelle": null,
        "Staat": "Parentland",
        "Strasse": "Parentenstrasse",
        "Telefon": "",
        "Website": "",
        "Ansprechpartners": []
      }
    },
    {
      "$ref": "4"
    }
  ],
  "Total": 2,
  "AggregateResults": null,
  "Errors": null
}


This leads to the following error:
Uncaught TypeError: Cannot read property 'Bezeichnung' of undefined
(anonymous function)
T.extend._rowsHtml kendo.all.min.js:18
T.extend.refresh kendo.all.min.js:18
b.isFunction.i jquery.min.js:3
i.extend.trigger kendo.all.min.js:9
nt.extend._process kendo.all.min.js:11
nt.extend.success kendo.all.min.js:11
b.isFunction.i jquery.min.js:3
n.success kendo.all.min.js:11
c jquery.min.js:3
p.fireWith jquery.min.js:3
k jquery.min.js:5
r

I would really appreciate any about this issue!

Best regards

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 05 Jul 2013, 09:06 AM
Hi Klaus,

Please note that currently the Grid supports only flat models out-of-the-box and I would recommend to flatter your model using View Model objects to avoid the serializing the properties which create the circular reference (refer to each other). I would suggest to check the "How do I avoid circular reference exceptions" FAQ section for further information.

Kind Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Masoud
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or