Reading from JSON Object Returning "No records found" in DataTable

Reading from JSON Object Returning "No records found" in DataTable

BeccaBecca Posts: 4Questions: 2Answers: 0

Testcase: https://live.datatables.net/fukedube/48

Debug: (from example; project's debug response is the same) Upload complete - owoqop -- https://debug.datatables.net/owoqop

Error message: "No records found", yet there are records in the data object JSON string. I've checked the string at jsonlint.com and it states valid JSON.

It is a set of nested objects. In the .NET project, the data object variable is created by converting a model object to a JSON string. In the example, that resultant string is just pasted in as a variable.

I'm sure it's simply down to me not calling the JSON values correctly from the string. But I'm pulling out my hair. I've tried, for instance:

dataObject
dataObject.CustomersList
dataObject.GenericResponse
dataObject.CustomersAsPicklist

dataObject
dataObject["CustomersList"]
dataObject["GenericResponse"]
dataObject["CustomersAsPicklist"]

dataObject
dataObject[0]
dataObject[1]
dataObject[2]

and so on.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    Answer ✓

    First `` is a string not a Javascript object. Instead of data: dataObject[0].CustomersList, use data: dataObject.CustomersList,. I made the two changes here:
    https://live.datatables.net/fukedube/49/edit

    Kevin

  • BeccaBecca Posts: 4Questions: 2Answers: 0
    edited April 2023

    Thank you!

    I had to also change the convert of the model to json object to:

    var dataObject = @Html.Raw(@JsonConvert.SerializeObject(Model.CustomersResponse));

    vs what I was using before.

Sign In or Register to comment.