Click here to Skip to main content
15,891,935 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a controller action with parameters that returns json data to feed jQuery datatable. So far I'm getting an empty table and ajax error: "...For more information about this error, please see http://datatables.net/tn/7" with the message "Loading..." in the table. Any help is highly appreciated.

public ActionResult GetItems(String description, string linenumber)
{
  ---retracted
   return Json(new { data = itemList }, JsonRequestBehavior.AllowGet);
}

Line Number: <input type="text" id="myInput1"><br>
Description: <input type="text" id="myInput2"><br>

<table class="table" id="ItemsTable">
<thead>
<tr>
<th>ID</th>
<th>Quantity</th>
</tr>
</thead>
</table>


What I have tried:

$(document).ready(function () {
var lnbr = $("#myInput1").val();
var desc = $("#myInput2").val()
var oTable = $('#ItemsTable').dataTable({
"ajax" : {
"url" : "/Home/GetItems",
"type" : "get",
"datatype" : "json",
"data" : { description:desc, linenumber: lnbr}
},
"columns": [(
{"data" : "ID", "autowidth" : true },
{"data" : "Qty", "autowidth" : true },
)]
});
});
Posted
Updated 13-Feb-18 10:41am
v3
Comments
JoCodes 12-Feb-18 23:44pm    
Can you check the Developer Console of the browser and share the error shown?
David_Wimbley 13-Feb-18 0:17am    
Have you see the nuget package for this? That may make things a bit easier for you.

https://github.com/mcintyre321/mvc.jquery.datatables
https://www.nuget.org/packages/Mvc.JQuery.Datatables

1 solution

"columns": [
{"data" : "ID", "autowidth" : true },
{"data" : "Qty", "autowidth" : true },
]
 
Share this answer
 
v4
Comments
Otitmach 13-Feb-18 17:29pm    
I had brackets in my columns array. It's working now. Thanks to everyone who tried to help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900