I am facing problem while using the object that i have sent from my controller to view using Json.
I am sending List of Objects to the View by using NewtonSoft.Json 7.x.x to serialize the List to Json. I am using the below code to serialize:
return JsonConvert.SerializeObject(DataToSend, Formatting.None, new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
I have 2 Entity Classes: 1) Form 2) FormFields
There is a 1-to-Many Relationship between these 2 entities.
public class Form
{
public long ID { get; set; }
public string Name { get; set; }
public virtual List<FormField> FormFields { get; set; }
}
public class FormField
{
public long FormID { get; set; }
public string FieldLabel { get; set; }
public string FieldType { get; set; }
public string FieldValue { get; set; }
public virtual Form form { get; set; }
}
I am trying to send the List of FormField to the view for rendering using Javascript. I am able to send it using the above serializaton Method.
But the problem is that, When i receive the Array of Objects in Javascript. It has Json Reference object IDs. I am not able to access those objects normally.
I am able to render the 1st FormField value in that array but i am not able to render rest of them. It is coming as Undefined.
I am attaching a screenshot of JSON Object Values which i am receiving on UI. You can see that there is an Object array. Each Object should have the Object of Type FormField and should have that field's value but there isn't.
Only the Object at index 0 is having the values and Rest of the Indexes have only Reference IDs.
Please help me resolve it.
Thanks
