2

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 AjaxHandlerdoes 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);


    }
3
  • I recall that its a little weird with the Ajax data, you may need to provide a first page of data when you first render the table. Commented Apr 8, 2013 at 19:38
  • Nothing showing in the network tab in developer tools on the browser? Commented Apr 8, 2013 at 19:40
  • Not in my main application. If I run the exact same code in a new project then I get the Json response in the network tab Commented Apr 8, 2013 at 19:50

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

8 Comments

I tried that too, but didn't help. If I set a break point in the AjaxHandler during debugging it is not even getting hit. I think it may be something in the script but not sure.
ActionResult is a 'super-set' of JsonResult so that shouldn't make a difference.
The AjaxHander is in the UX controller
Is this view populated from a different controller that ux?
No. It is all part of the UX controller
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.