ASP.NET Core retrieving datatable params

ASP.NET Core retrieving datatable params

plazavplazav Posts: 6Questions: 2Answers: 0
edited April 2018 in Free community support

Hi!
I am trying this example: Using jQuery DataTables Grid With ASP.NET CORE MVC
But I can't get any param with construction like:

 var length = Request.Form["length"].FirstOrDefault();  

I need them as I want to make paging.

Answers

  • allanallan Posts: 63,332Questions: 1Answers: 10,436 Site admin

    Are you telling DataTables' ajax option to POST the data? See this example for how to do that.

    Allan

  • plazavplazav Posts: 6Questions: 2Answers: 0

    Yes, sure. Here is my client side code:

     $('#texts-dataTable').DataTable({
                "serverSide": true,
                "ajax": {
                    "type": "POST",
                    "datatype": "json",
                    headers: { 'RequestVerificationToken': gettoken() },
                    "url": '@Html.Raw(Url.Action("DataHandler", "Home", 
                                new { someparam = 1 }))',
                    'data': function (data) {
                        data = JSON.stringify(data);
                        data.iStart = 10;
                        return data;
                    }
                },
                "processing": true,
                "paging": true,
                "order": [[1, "desc"]]
            });
    
  • allanallan Posts: 63,332Questions: 1Answers: 10,436 Site admin

    You'd probably need to contact the author of that post or post in a C# forum in that case. On the client-side it looks like you are doing what I would expect. I'm not sure why that isn't working.

    Allan

  • plazavplazav Posts: 6Questions: 2Answers: 0

    Seems the solution was to remove:

    data = JSON.stringify(data);
    

    and

    "datatype": "json",
    
This discussion has been closed.