Reputation: 556
I am trying to integrate the jQuery DataTables plugin into an ASP.Net MVC project. I am following the example here. When I run just the sample code in a test project everything works. But when I try and debug it in my real application the AjaxHandler
does not even get executed. Am I missing something?
Here is the calling jQuery Code:
$(document).ready(function () {
$('#myDataTable').dataTable({
"bServerSide": true,
"sAjaxSource": "/UX/AjaxHandler",
"bProcessing": true,
"aoColumns": [
{
"sName": "ID",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '<a href=\"Details/' + oObj.aData[0] + '\">View</a>';
}
},
{ "sName": "NAME" },
{ "sName": "ADDRESS" },
{ "sName": "TOWN" },
]
});
});
</script>
Then my handler;
public ActionResult AjaxHandler(jQueryDataTableParamModel param)
{
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = 97,
iTotalDisplayRecords = 3,
aaData = new List<string[]>() {
new string[] {"1", "Microsoft", "Redmond", "USA"},
new string[] {"2", "Google", "Mountain View", "USA"},
new string[] {"3", "Gowi", "Pancevo", "Serbia"}
}
},
JsonRequestBehavior.AllowGet);
}
Upvotes: 2
Views: 599
Reputation: 4406
If the call to this view is being made from another controller other than ux:
"sAjaxSource": "ux/AjaxHandler",
If the call to this view is made from ux then you only need:
"sAjaxSource": "AjaxHandler",
The extra slash you have in front of the ux is causing your grief
Also I as per our discussion your Id on your table was not the same as the ID your JS was referencing.
Upvotes: 2