Datatable sorting,paging at server side..unable to read start,length values at server side.

Datatable sorting,paging at server side..unable to read start,length values at server side.

MP1223MP1223 Posts: 7Questions: 2Answers: 0

I'm trying to implement server side paging and sorting.I couldn't get value for request["length"] etc..
I got some 500 (Internal Server Error)
Could you please have look and let me know where i was missing.Thanks in advance.

Here is my Controller.cs

public JsonResult ImportKFSData()
{

        string startDate = "01/01/2016";
        string endDate = "01/15/2016";
        //int totalrows = 0;
        var _KFSImportList = new List<KFSPaymentDetail>();
        List<KFSPaymentDetail> _KFSImportPaymentDetailOrderBy;
        // var draw = Request.Form.GetValues("draw").FirstOrDefault();
        int start = Convert.ToInt32(Request.QueryString["start"]);
        int length = Convert.ToInt32(Request.QueryString["length"]);

        string searchValue = Request.QueryString["search[value]"];
        string sortColumnName = Request.QueryString["columns[" + Request.QueryString["order[0][column]"] + "][name]"];
        string sortDirection = Request.QueryString["order[0][dir]"];

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

            _KFSImportList = KFSPaymentDetailList.GetKFSImportList(Convert.ToDateTime(startDate), Convert.ToDateTime(endDate), "test").ToList();
            Session["KFSImport"] = _KFSImportList;

        }
        int totalrows = _KFSImportList.Count;

        if (!string.IsNullOrEmpty(searchValue) && _KFSImportList.Count >= 1) // Filter
        {
            _KFSImportPaymentDetailOrderBy = _KFSImportList.Where(x => x.CheckNumber.ToString().Contains(searchValue.ToLower()) || x.Amount.ToString().Contains(searchValue.ToLower()) ||
            x.PayeeName.ToLower().Contains(searchValue.ToLower()) || x.PayeeId.ToString().Contains(searchValue.ToLower()) || x.PaymentDate.ToString().Contains(searchValue.ToLower())).ToList();

            _KFSImportList = _KFSImportPaymentDetailOrderBy;
        }

        int totalrowsafterfiltering = _KFSImportList.Count();

        ////sorting

        if (!((string.IsNullOrEmpty(sortColumnName)) && string.IsNullOrEmpty(sortDirection)))
        {
            _KFSImportList = _KFSImportList.OrderBy(sortColumnName + "" + sortDirection).ToList<KFSPaymentDetail>();

        }

        //Paging

        _KFSImportList = _KFSImportList.Skip(start).Take(length).ToList<KFSPaymentDetail>();

        return Json(new { data = _KFSImportList, draw = Request["draw"], recordsTotal = totalrows, recordsFiltered = totalrowsafterfiltering }, JsonRequestBehavior.AllowGet);

    }

}

Here is my Js.

$(document).ready(function () {
    debugger;
    var KFSImportTable = $('#KFSImporttbl').DataTable({
        "serverSide": true,
        "ajax": {
            "url": '@Url.Action("ImportKFSData", "KFSReportablePayments")',
            "type": "POST",
            "dataType": "json",
            "dataSrc": "Data",
            "contentType": "application/json; charset=utf-8"
        },
        "processing": true,
        "language":{
        "processing":"processing....Please wait"
        },
        //"bSort": true,
        "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": 700,
        "scrollX": true,
        "lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "All"]],
        "order": [[0, "asc"]],
        "aaSorting": []




    });
});

Answers

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

    500 (Internal Server Error)

    To troubleshoot 500 Internal Server Error you will need to start by looking at the server logs to see why it is returning the 500 error.

    Kevin

  • MP1223MP1223 Posts: 7Questions: 2Answers: 0
    edited November 2017

    System.InvalidOperationException: A circular reference was detected while serializing an object of type '_1099.MISC.Core.KFSPaymentDetail'.

  • MP1223MP1223 Posts: 7Questions: 2Answers: 0
    edited November 2017

    I fixed the above one.but when I'm debugging , I can see that int length = Convert.ToInt32(Request.QueryString["length"]); is 0.why i couldn't see default value 10..?Do I need to set any property at script level..?

  • MP1223MP1223 Posts: 7Questions: 2Answers: 0

    var start = Request.Form.GetValues("start").FirstOrDefault();
    I have tried with above statement.I got error like "Value cannot be null.
    Parameter name: source"

    Exception Details: System.ArgumentNullException: Value cannot be null.
    Parameter name: source

    Can any one help me ..how to retrieve start,length values from form..

This discussion has been closed.