i have searched but nothing that help me i have found. I have this JSON:
{
"id": 1,
"customer_ID": 1,
"address": {
"id": 1,
"description": "primary address"
}
},{
"id": 2,
"customer_ID": 2,
"address": {
"id": 2,
"description": "primary address"
}
}
And if i try to add to my DataTables i have an error:
Requested unknown parameter 'id' for row 0, column 0
But, if i convert my JSON to this, the table is filled:
{"data": [
{
"id": 1,
"customer_ID": 1,
"address":
{
"id": 1,
"description": "primary address"
}
},{
"id": 2,
"customer_ID": 2,
"address":
{
"id": 2,
"description": "primary address"
}
}]}
This is my Javascript code:
$("#tblCustomerAddress").DataTable({
data: result,
destroy: true,
columns: [
{ "data": 'id' },
{ "data": 'address.description' },
{ "data": 'customer_ID' }
]
});
The "result" field is returned by my C# code:
public async Task<IActionResult> OnPostSaveAddressAsync(string GUID, string Address)
{
...
JsonResult Json = new JsonResult(wItem.Address_List);
return Json;
}
My question is: how can i add this {data: []} to my JSON without manipulate with a stringbuilder? There are no default function that cover this?