I faced a challenge while trying to populate a jQuery datatable with data from my database. After some research, I believe the issue lies in the json format returned by my controller. The expected format should be:
{
"data": [
{
"ID": "1",
"CODIGO": "CC0050",
"TEXTO": "USINAGEM"
},
{
"ID": "2",
"CODIGO": "CC0100",
"TEXTO": "MONTAGEM"
}]
}
However, the current format being returned is:
[
{
"ID":24,
"CODIGO":"CC0050",
"TEXTO":"USINAGEM"
},
{
"ID":25,
"CODIGO":"CC0100",
"TEXTO":"MONTAGEM"
}
]
This is the code snippet from the controller:
[HttpGet]
public JsonResult GetAllCECOS()
{
using (RPIEntities contextObj = new RPIEntities())
{
try
{
var listaCECOS = contextObj.T0CECOS.ToList();
return Json(listaCECOS, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
throw ex;
}
}
}