1

I have a datatable that is being populated via serverside ajax. I need to pass variables to the serverside C# method. The variables are not getting to the serverside.

I've tried a few different approaches. It should be pretty easy.

 var tblApplication = $('#tblApplication').DataTable({
    "ajax": {
        "url": '../../Search/ApplicationList',
        "type": 'POST',
        "data":{
            yearh: 2014,
            make: ''
        }
    },        
    "autoWidth": false,
    "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
        $(nRow).addClass("parent");
        return nRow;
    },
    "order": [[1, "desc"]],
    "deferRender": true,
    "columns": [
        {
            "title": '',
            "class": 'details-control',
            "orderable": false,
            "data": null,
            "defaultContent": '<img src="../../assets/images/details_open.png" />'
        },
        { "title": 'ApplicationId', "data": 'ApplicationId', "visible": false },
        { "title": 'Year', "data": 'Year' },
        { "title": 'Make', "data": 'Make' },
        { "title": 'Model', "data": 'Model' },
        { "title": 'Qualifier', "data": 'Qualifier' },
        { "title": 'Axle', "data": 'Axle' },
        { "title": 'Pad Set', "data": 'PadSet' },
        { "title": 'Side', "data": 'Side' },
        { "title": 'Part List', "data": 'PartListId' }
    ]
});

[HttpPost]
public JsonResult ApplicationList(int year = 0, string make = null )
{
}
Jim Kiely
  • 365
  • 2
  • 6
  • 24

1 Answers1

0

According to datatables.js reference you need to extend "data" something like following to make it work;

$('#example').dataTable( {
  "ajax": {
    "url": "data.json",
    "data": function ( d ) {
      return $.extend( {}, d, {
        "extra_search": $('#extra').val(),
        "year": 2014,
        "make": 'Nissan'
      } );
    }
  }
} );

For further documentation please see the this. Hope this helps.

Mahib
  • 3,977
  • 5
  • 53
  • 62