Unable to render data to Datatable when its more than 8 columns.

Unable to render data to Datatable when its more than 8 columns.

MP1223MP1223 Posts: 7Questions: 2Answers: 0

I have a Datatable that when I add more than eight columns it won't render. I am using GET on an ajax request and pushing the data to the Datatable. I was unable to call my action method in controller after adding 9th column.But i was working just fine calling action method in controller and rendering to data table.

I got 404 Error and got popup msg saying DataTables warning: table id=KFSImporttbl - Ajax error. For more information about this error, please see http://datatables.net/tn/7.

Can anyone pls help me on this.Thanks!!

here is my HTML~~~~:

Payment Date Payee Name Src Doc Type Amount Check Number Object Code KFSDocNbr Tax TypeCode TIN
Payment Date Payee Name Src Doc Type Amount Check Number Object Code KFSDocNbr Tax TypeCode TIN

here is my script

$(document).ready(function () {
    debugger;
    var KFSImportTable = $('#KFSImporttbl').DataTable({
        "serverSide": true,

        "ajax": {
            "url": '@Url.Action("ImportKFSData", "KFSReportablePayments")',
            "dataType": "json",

            "type": "GET"
            // "contentType": "application/json; charset=utf-8"
        },

        "bProcessing": true,
        "bSort": true,
        "dataSrc": "Data",
        "columns": [
                        {
                            "data": "PaymentDate"  },                          

                        { "data": "PayeeName" },
                        { "data": "SrcDocType" },
                        { "data": "Amount" },
                         { "data": "CheckNumber" },
                          { "data": "ObjectCode" },
                           { "data": "KFSDocNbr" },
                              { "data": "TaxTypeCode" },
                              { "data": "TIN" }
                              //{ "data": "AddressLine1" },
                              //{ "data": 'AddressLine2' },
                              //{ "data": 'City' },
                              // { "data": 'State' },
                              // { "data": 'Country' },
                              //  { "data": 'ZipCode' },
                              //   { "data": 'VendorOwnerCode' },
                              //     { "data": 'ReasonCode' }
        ],
        "scrollY": 500,
        "scrollX": 400,
        "paging": false

    });
});

Here is my Controller.cs

 public JsonResult ImportKFSData()
    //(int rows,string sidx,string sord,int page)//,DateTime startDate,DateTime endDate)
    {

        string startDate = "01/01/2016";
        string endDate = "01/15/2016";
        int page = 1;
        var _KFSImportList = new KFSPaymentDetailList();

        if (Session["KFSImport"] != null)
        {
            //If so access it here
            _KFSImportList = Session["KFSImport"] as KFSPaymentDetailList;
        }
        else
        {

            // var _KFSImportList = new KFSPaymentDetailListViewModel(Convert.ToDateTime(startDate), Convert.ToDateTime(endDate), "mareedum");
            _KFSImportList = KFSPaymentDetailList.GetKFSImportList(Convert.ToDateTime(startDate), Convert.ToDateTime(endDate), "mareedum");
            Session["KFSImport"] = _KFSImportList;
        }

        var result = new
        {
            total = 50,
            Page = page.ToString(),
            records = _KFSImportList.Count(),
            Data = _KFSImportList.Select(kfsRawData => new
            {
                kfsRawData.PaymentDate,
                kfsRawData.PayeeId,
                kfsRawData.PayeeName,
                kfsRawData.SrcDocType,
                kfsRawData.Amount,
                kfsRawData.CheckNumber,
                kfsRawData.ObjectCode,
                kfsRawData.KFSDocNbr,
                kfsRawData.TaxTypeCode,
                kfsRawData.TIN,
                kfsRawData.AddressLine1,
                kfsRawData.AddressLine2,
                kfsRawData.City,
                kfsRawData.State,
                kfsRawData.ZipCode,
                kfsRawData.Country,
                kfsRawData.VendorOwnerCode,
                kfsRawData.ReasonCode
            }).ToArray()
        };

        return Json(result, JsonRequestBehavior.AllowGet);

    }

}

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    You will probably need to review your server logs to determine exactly why its returning a 404 error. Might be that with the additional columns the GET request is larger than the server will accept. Can you try using POST?

    Kevin

  • MP1223MP1223 Posts: 7Questions: 2Answers: 0

    Yes, I tried with Post as well. I got same issue with that too..

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    What do the server logs have regarding the 404 error?

    Kevin

  • MP1223MP1223 Posts: 7Questions: 2Answers: 0

    Yes..I got it after changing to POST.earlier i din't change the attribute type to [httpPost] in my controller.Its worked now.Thanks you so much..

This discussion has been closed.