Requested unknown parameter 'Name' for row 0 in Asp Mvc ?

Requested unknown parameter 'Name' for row 0 in Asp Mvc ?

NevradubNevradub Posts: 2Questions: 1Answers: 0

Hello,

I have a problem when i refresh my page with dataTable. Have a alert with this error. Requested unknown parameter 'Name' for row 0.

This is my code js:

$(document).ready(function () {
$('#example').DataTable({
"processing": true,
"serverSide": true,
"datatype": "json",
"ajax": {
"url": "GetData",
"type": "GET"
},
"aoColumnDefs": [
{ "data": "Name", "autoWidth": true },
{ "data": "Firstname", "autoWidth": true },
{ "data": "Age", "autoWidth": true },
{ "data": "Dob", "autoWidth": true },
{ "data": "Email", "autoWidth": true }
]
});
})

This is my controler:

[HttpGet]
public ActionResult GetData()
{
int elem = Database.students().Count;
string json = JsonConvert.SerializeObject(Database.students());
return Json(new { data = json},JsonRequestBehavior.AllowGet);
}

This is my response json in Xhr:

{"data":"[{\"Name\":\"Salut\",\"Firstname\":\"Salut\",\"Age\":1,\"Dob\":\"1010-10-10T00:00:00\",\"Email\":\"nevra@lol.com\"}]"}

I look documentation for this error but i don't understand where is my problem.

Thank's you so much.

Answers

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    Your data is not an array, it is a string. You also aren't returning the required parameters for server-side processing (do you need server-side processing? Do you have tens of thousands of rows?). See the documentation for details.

    Allan

  • NevradubNevradub Posts: 2Questions: 1Answers: 0

    This project is a test to see if it is possible to integrate Datatable my final project.

    Yes it is a string , but why I have this error? My side js code is not correct ?

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    Yes it is a string , but why I have this error?

    You answered your own question. You have that error, because it is a string. The data parameter should be an array. Please see the documentation.

This discussion has been closed.