EDIT # 1
The reason you get a type error is due to the wrong table, which you seem to already know. You also indicated that the table is created dynamically, so we are going to dynamically add the table header using server code to dynamically write columns
sTitle will provide table headers in absentia (sClass just provides a row class)
<script type="text/javascript> $('#TestDatatable').dataTable({ "bProcessing": true, "bServerSide": true, "sAjaxSource": "Search/Testcall", "aoColumns": [ { "sTitle": "Engine" }, { "sTitle": "Browser" }, { "sTitle": "Platform" }, { "sTitle": "Version", "sClass": "center" }, { "sTitle": "Grade", "sClass": "center" } ], ...
What was about to happen was to create an initial request to run before the ajax request (since they are not connected).
The purpose of this query is to collect the column names of the table, it may be the same query as the original one, we just need the column names (please excuse my asp.net syntax, not sure if it is correct, but you will get the idea)
Datatables function
<script type="text/javascript> $('#TestDatatable').dataTable({ "bProcessing": true, "bServerSide": true, "sAjaxSource": "Search/Testcall", "aoColumns": [ <% for each ColumnList as Column { '{ "sTitle": "'& Column &'" },' } %> ], //aoColumns end "fnServerData": function (sSource, aoData, fnCallback, oSettings) { aoData.push({ "name": "more_data", "value": "my_value" }); oSettings.jqXHR = $.ajax({ "dataType": 'json', "type": "POST", "url": sSource, "data": aoData, "success": fnCallback }); } }); </script>
theoretical above but should work
Original answer The reason you get a type error is due to the wrong table that you thought you already knew. You also indicated that the table is created dynamically
Best way: let datatables do the work for you
<table> <thead><tr><th>Group</th><th>Code</th><th>Account</th><th>Type</th></tr></thead> <tbody></tbody> </table>
Above all you need for html in cshtml file
Now your json call should really return data (child steps)
I do not know that I am familiar with asp.net json encoding, I usually use ashx handlers in C # when working with .net, however the bottom line is the ajax url that you use should return the next json for server-side implementations, exceptions for dt_rowid and dtrowclass they are optional fields to either assign identifiers or tr-string classes)
{ "sEcho": 3, "iTotalRecords": 57, "iTotalDisplayRecords": 57, "aaData": [ { "DT_RowId": "row_7", "DT_RowClass": "gradeA", "0": "Gecko", "1": "Firefox 1.0", "2": "Win 98+ / OSX.2+", "3": "1.7", "4": "A" }, ...
Datatables will generate tr td html for you if you give it well-formed json
Finally, your datatables function will need bServerSide to set true, and your fnRowCallback looks fine
The previous method I did that did not use data strength:
<table> <thead><tr><th>Group</th><th>Code</th><th>Account</th><th>Type</th></tr></thead> <tbody> @foreach ( var i in dataset) { '<tr><td>...</td></tr>' } </tbody> </table>
Documents for linking to typeerror On the use page:
In order for DataTables to function correctly, the HTML for the target table must be built in a well-formed form using the sections "thead" and "tbody" declared.
In your case, the <thead> and <tbody> sections are missing ... add the ones that will be fixed for your typeerror k undefined object
We can fix ajax after resolving a type error, but at first glance it seems that your controller is configured to receive, while your ajax data is set to publish, install ajax to receive and check if this fixes the problem.