I am trying to use JQuery Datatable plugin in ASP.NET MVC application. However, although my controller returns JSON data to plugin, the table shows a Loading...
message and stuck there.
This is my controller,
public ActionResult GetCompanies(jQueryDataTableParamModel param)
{
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = 97,
iTotalDisplayRecords = 3,
aaData = new List<string[]>() {
new string[] {"1", "a1", "a2", "a3"},
new string[] {"2", "b1", "b2", "b3"},
new string[] {"3", "c1", "c2", "c3"}
}
}, JsonRequestBehavior.AllowGet);
}
This is the initialization of datatable plugin.
$('#companyDataTable').dataTable({
bProcessing: true,
sAjaxSource: '@Url.Action("GetCompanies", "Company")'
});
This is the screenshot of my table.
This is the JSON data returned to plugin from Company/GetCompanies
{ "sEcho":null,
"iTotalRecords":97,
"iTotalDisplayRecords":3,
"aaData":[ ["1","a1","a2","a3"],
["2","b1","b2","b3"],
["3","c1","c2","c3"]
]
}
jQuerDataTableParamModel
is a class which is shown here. I also tried answers on this question but none of them are working for me.
EDIT :
This is how plugin request looks like.
Any ideas ?
Thanks
param
model is not initialized for some reason. Try to check request parameters in browser, using developer tools. Also, try to change the argument name - maybe you have another request parameter calledparam
. – Miroslav Popovic Jul 5 '12 at 16:07'GetCompanies'
? No@Url.Action
call? That should work if you are currently on/Company
page... then/Company/GetCompanies
should be requested. Not sure why it's not working with@Url.Action
. – Miroslav Popovic Jul 5 '12 at 16:40