1

I was wandering if its possible to pass in a different parameter to a controller using Ajax.reload() in datatables.

thanks to another topic on stackoverflow, I was able to pass in parameter from my variable in to url.Action on creating the table new { cyfy = "_Switch" })".replace("_Switch",Switch)

Then on button click i change the state of the variable ( to 0 or 1 ) and call Ajax.reload() on my table.

The issues is that controller receives the same parameter value on each reload. It seems that this part is not run with the reload:

 "ajax": {
           "url": "@Url.Action("GetProjects", "mytool",new { cyfy = "_Switch" })".replace("_Switch",Switch),
            "type": "get",
            "datatype": "json"
         },

I was wandering if there is a way to pass in different parameter value on datatables ajax.realod ?

Below bigger part of the code:

                     $("#toggle").change(function () {


                     if ($('#toggle').is(':checked') == true) {

                         Switch = 1
                     }
                     else {
                         Switch = 0
                     }
/////////////////

          var oTable = $('#myDatatable').DataTable({
                             "bPaginate": false,
                              dom: 'Bifrtp',
                             "ajax": {
                                 "url": "@Url.Action("GetProjects", "mytool",new { cyfy = "_Switch" })".replace("_Switch",Switch),
                                 "type": "get",
                                 "datatype": "json"
    },

1 Answer 1

1

Solved. The issue was that Ajax was adding timestamp to the request on the reload.

to solve this I have added cache : true, option while creating a table.

and then I am reloading the table using ajax.url

 var testURL = CreateUrl("mytool/GetProjects?cyfy=") + Switch;
 $('#myDatatable').DataTable().ajax.url(testURL).load();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.