Extra Ajax Parameter - how do I access it in the controller ?

Extra Ajax Parameter - how do I access it in the controller ?

duggieduggie Posts: 5Questions: 2Answers: 0
edited July 2019 in Free community support

Hi, I want to add extra parameters to the Ajax request that is creating my DataTable. I have seen that I can add a parameter to "data" in the ajax part of the jquery request, but I don't know how to consume that in my c# controller. (My project is ASP.NET MVC5).

This is my jquery script :-1:

 var resultVM;
        $(function () {
            resultVM = {
                dt: null,

                init: function () {
                    dt = $('#results-table').DataTable({
                        "serverSide": true,
                        "processing": true,
                        "ajax": {
                            "url": "@Url.Action("GetResults","Result")",
                            "data": function (d) {
                                d.Percentage = "50"
                            }
                        },
                        "columns": [
                            { "title": "SITE NAME", "data": "site_name", "searchable": true },
                            { "title": "IP ADDRESS", "data": "ip_address", "searchable": true },
                            { "title": "SPEED RESULT (mbps)", "data": "speed_result", "searchable": true },
                            { "title": "DIRECTION", "data": "direction", "searchable": true },
                            { "title": "TEST DATE/TIME", "data": "test_datetime", "searchable": true },
                            { "title": "LINESPEED - DOWN", "data": "linespeed_down", "searchable": true },
                            { "title": "LINESPEED - UP", "data": "linespeed_up", "searchable": true }
                        ],
                        "lengthMenu": [[10, 25, 50, 100], [10, 25, 50, 100]],
                        "pagingType": "full_numbers"
                    });
                }
            }

            // initialize the datatables
            resultVM.init();
        });

So I have added an extra parameter here

"data": function (d) {
          d.Percentage = "50"
}

but when this gets passed to my controller, the object type is DefaultDataTablesRequest which doesn't seem to have the extra parameter in it. Can someone please point me in the right direction here ? Thanks.

This discussion has been closed.