how to send data param to controller by using datatabel

how to send data param to controller by using datatabel

yogi1982yogi1982 Posts: 2Questions: 2Answers: 0

i am trying to get list view on from date and to date param bu i cant understand how to do

jquery

            $("#PTable").dataTable({
                    "serverSide": true,
                    "ajax": {
                        "type": "POST",
                        "url": "/Perchus/ListGetINV3",
                        "data": function (data) { return data = JSON.stringify(data) },
                        "data": '{"txtFromDate":"txtFromDate" ,"txtToDate":"txtToDate" }',   
                        "contentType": 'application/json; charset=utf-8',
                        "datatype": "json"
                    },
                    "columns": [
                        { "data": "SypplyerName", "orderable": true },
                        { "data": "InvoiceNo", "orderable": true },
                        { "data": "InvoiceDate", "orderable": true },
                        { "data": "TaxAmount", "orderable": true },
                        { "data": "TotalAmount", "orderable": true },
                    ],
                    //"order": [[0, "asc"]]
                });

controller

[HttpPost]
public JsonResult ListGetINV3(DateTime txtFromDate,DateTime txtToDate)
{
PerchesTransaction pt = new PerchesTransaction();
var pdata = dc.PerchesTransactions.Where(m=>m.InvoiceDate >= txtFromDate && m.InvoiceDate <= txtToDate).ToList();
return Json(pdata, JsonRequestBehavior.AllowGet);
}

Answers

  • colincolin Posts: 15,210Questions: 1Answers: 2,592

    Hi @yogi1982 m

    You've got ajax.data declared twice - there should be only the one.

    Cheers,

    Colin

  • YogisYogis Posts: 1Questions: 0Answers: 0

    thanks , colin
    but he say error
    DataTables warning: table id=PTable - Ajax error. For more information about this error, please see http://datatables.net/tn/7
    and didn't show any data

    "ajax": {
    "type": "POST",
    "url": "/Perchus/ListGetINV3",
    "data":'{"txtFromDate":"txtFromDate","txtToDate":"txtToDate"}',
    "contentType": 'application/json; charset=utf-8',
    "datatype": "json"
    },

  • kthorngrenkthorngren Posts: 20,690Questions: 26Answers: 4,840

    Follow this link in the message for troubleshooting steps:
    http://datatables.net/tn/7

    Let us know what you find.

    Kevin

This discussion has been closed.