Uncaught TypeError: Cannot read property 'length' of undefined
Uncaught TypeError: Cannot read property 'length' of undefined

Hi All. I searched everyware but with no success trying to fix the error. I want to use server side processing to display large (over 4000 records) data from database. I'm using ASP MVC and EF. Here is my code:
public JsonResult HostsJSON()
{
IEnumerable<vw_Host> lst_Host_DB;
lst_Host_DB = Host.GetAllActive();
var result = Json(lst_Host_DB, JsonRequestBehavior.AllowGet);
return result;
}
<script type="text/javascript">
$(document).ready(function () {
applyFullDatatable('#tblHosts');
var columnsExport = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
function applyFullDatatable(tableholder) {
$(tableholder).DataTable({
dom: 'l<Bf>tip',
scrollX: true,
lengthMenu: [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
scrollY: 440,
scrollCollapse: true,
bSortClasses: false,
ajax: {
url: "@(Url.RouteUrl("HostsJSON"))",
type: "POST"
},
buttons: [
{
extend: 'copy',
text: 'Copy to clipboard',
exportOptions: {
columns: columnsExport
}
},
{
extend: 'csv',
text: 'Export to CSV',
title: 'Hosts',
exportOptions: {
columns: columnsExport
}
},
{
extend: 'excel',
text: 'Export to XLSX',
title: 'Hosts',
exportOptions: {
columns: columnsExport
}
}
]
});
};
});
</script>
This discussion has been closed.
Answers
Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.
Information on how to create a test page, if you can't provide a link to your own page can be found here.
Thanks,
Allan
Hi allan. Thank you for your reply. Unfortunately I can't post the page there. On the other hand I found that when I added line:
dataSrc: ""
error changed to:
DataTables warning: table id=tblHosts - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
In my Controller I am returing IDs which are not in HTML. Do you think the issue is related the the columns mapping? On my HTML page I am displaying fields without IDs.
Please let me know if my explanations are not clear.
Can you show me the Ajax it is returning. If a link can't be given, can you use the debugger please.
Allan
Hi allan - I made some progress. I've added below code:
columns: [
{ "data": "SystemName" },
{ "data": "ApplicationName" },
{ "data": "Hostname" }
],
and it started to work. My question is - why search option is not working? I mean when I type something in search box the table is not filtered. Additionally record count is showing:
Showing 0 to 0 of 0 entries
Is it necessary to put these lines:
columns: [
{ "data": "SystemName" },
{ "data": "ApplicationName" },
{ "data": "Hostname" }
],
It is additional thing that has to be maintained and I would like to control the columns from model.
I also tested this and it works when amount of rows is about 1000. When I am trying do display about 2000 records below error occurred:
DataTables warning: table id=tblHosts - Ajax error. For more information about this error, please see http://datatables.net/tn/7 - Failed to load resource: the server responded with a status of 500 (Internal Server Error)
I'm afraid I don't know - I'd need more information such as that offered by the debugger.
For a 500 internal error you would need to refer to your server's error log to see what error message is being reported there.
Allan