Retrieve Paging / Sorting /Searching variable in POST method.

Retrieve Paging / Sorting /Searching variable in POST method.

kalpesh2804kalpesh2804 Posts: 10Questions: 3Answers: 1

i am not able to find Searching / Sorting / Paging variable in server side if i used POST method in Asp.Net Webforms.

I attached my example here with.

https://www.dropbox.com/s/sj37qk0fe5jz6qe/JqDatatablesWebForm.zip?dl=0

thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    I'm afraid I don't quite understand what you mean. Do you mean you can't read the values that are being posted by DataTables if you have the serverSide option enabled? If so, use Request.Form to get the data.

    Allan

  • kalpesh2804kalpesh2804 Posts: 10Questions: 3Answers: 1
    edited February 2018

    yes, i enabled ServerSide Option but still i can't read value if i use POST method instead of GET.

    I tried Request.Form but still getting null value for length,start,etc..

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    Have you told DataTables to actually send a POST request? e.g.:

    ajax: {
      url: ...,
      type: 'post'
    }
    

    The default is GET.

    Allan

  • kalpesh2804kalpesh2804 Posts: 10Questions: 3Answers: 1

    I already used POST but still not working

    Code Sample:

    $(document).ready(function ()
    {
        $('#TableId').DataTable(
        {
            "columnDefs": [
                { "width": "5%", "targets": [0] },
                { "className": "text-center custom-middle-align", "targets": [0, 1, 2, 3, 4, 5, 6] },
            ],
            "language":
                {
                    "processing": "<div class='overlay custom-loader-background'><i class='fa fa-cog fa-spin custom-loader-color'></i></div>"
                },
            "processing": true,
            "serverSide": true,
            "ajax":
                {
                    "url": "Default.aspx/GetData",
                    "contentType": "application/json",
                    "type": "POST",
                    "dataType": "JSON",
                    "data": function (d)
                    {
                        return JSON.stringify(d);
                    },
                    "dataSrc": function (json)
                    {
                        json.draw = json.d.draw;
                        json.recordsTotal = json.d.recordsTotal;
                        json.recordsFiltered = json.d.recordsFiltered;
                        json.data = json.d.data;
    
                        var return_data = json;
                        return return_data.data;
                    }
                },
            "columns": [
                        { "data": "Sr" },
                        { "data": "OrderTrackNumber" },
                        { "data": "Quantity" },
                        { "data": "ProductName" },
                        { "data": "SpecialOffer" },
                        { "data": "UnitPrice" },
                        { "data": "UnitPriceDiscount" }
            ]
        });
    });
    
    
  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    I'm afraid I don't have access to a Windows PC just at the moment so I cant run your project.

    Can you show me your controller's code please?

    Allan

  • kalpesh2804kalpesh2804 Posts: 10Questions: 3Answers: 1
    edited June 2018 Answer ✓
               "ajax":
                    {
                        "type": "POST",
                        "method": "POST",
                        "url": "Default.aspx/GetData",
                        "contentType": "application/json",
                        "data": function (d) {
                            return JSON.stringify({ "objModel": d });
                        },
                        "dataSrc": function (json) {
                            json.draw = json.d.draw;
                            json.recordsTotal = json.d.recordsTotal;
                            json.recordsFiltered = json.d.recordsFiltered;
                            json.data = json.d.data;
                            return json.data;
                        }
                },
    

    I used above to code in POST method.

    and its working fine.

This discussion has been closed.