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 )
{
}
4
  • a mistake? in the ajax call you write "yearh" and in the method "year"... can check that? Commented Aug 12, 2014 at 18:58
  • Nope that is not it. Commented Aug 12, 2014 at 19:22
  • have a look at this example Commented Aug 12, 2014 at 19:49
  • It is datatable .js and the syntax for this is not going to be like a reqular jquery ajax call. Something is wrong with the js ajax call. Commented Aug 12, 2014 at 19:53

1 Answer 1

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.

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.