I have 300,000+ rows, when I test my project the Datatable is loading for about 30sec then this error occured
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
btw I am using Jquery Datatables, this is my code:
HomeController.cs:
public JsonResult GetAllRecords()
{
var records = GetRecords().ToList();
return Json(new { data = records }, JsonRequestBehavior.AllowGet);
}
Javascript:
var FilterSAR = $('#RecordsDatatable').DataTable({
"ajax": {
"url": '/Home/GetAllRecords',
"type": "get",
"datatype": "json"
},
"columns": [
{ "data": "ssn_or_tin", "autoWidth": true },
{ "data": "cusid", "autoWidth": true },
{ "data": "accountNo", "autoWidth": true },
{ "data": "dateTrans", "autoWidth": true },
{ "data": "transCode", "autoWidth": true },
{ "data": "transdescription", "autoWidth": true },
{ "data": "amount", "autoWidth": true },
{ "data": "cashin", "autoWidth": true },
{ "data": "cashout", "autoWidth": true },
{ "data": "source", "autoWidth": true }
]
});
Index.chtml
<table class="table table-hover table-bordered" id="RecordsDatatable">
<thead>
<tr>
<th>SSN or TIN</th>
<th>Customer ID</th>
<th>Account Number</th>
<th>Date Transaction</th>
<th>Trans Code</th>
<th>Trans Description</th>
<th>Amount</th>
<th>Cash in</th>
<th>Cash out</th>
<th>Source</th>
</tr>
</thead>
</table>
Then i searched for solutions online and i found this code:
public JsonResult GetAllRecords()
{
var jsonResult = Json(GetRecords().ToList(), JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
The error is gone but my records are still not showing, i think it has something to do with the Json code, I also found other solution like the Serialize but i can't seem to make it work with my code maybe because i am using JsonResult not ContentResult, I'm not sure.

