locked
Uncaught TypeError RRS feed

  • Question

  • User-797751191 posted

    Hi

      Uncaught TypeError: Cannot read property 'length' of undefined
    at jquery.dataTables.min.js:48
    at i (jquery.dataTables.min.js:35)
    at Object.success (jquery.dataTables.min.js:35)
    at fire (jquery-1.10.2.js:3062)
    at Object.fireWith [as resolveWith] (jquery-1.10.2.js:3174)
    at done (jquery-1.10.2.js:8249)
    at XMLHttpRequest.callback (jquery-1.10.2.js:8792)

    $(document).ready(function () {
        $("#tblUser").DataTable({
    
            "ajax": {
                "url": "/Home/List",
                "type": "GET",
                "datatype": "json"
            },
            "columns": [
                    { "data": "UserName", "name": "UserName", "autoWidth": true },
                    { "data": "Password", "name": "Password", "autoWidth": true },
                    { "data": "FirstName", "name": "FirstName", "autoWidth": true },
                    { "data": "LastName", "name": "LastName", "autoWidth": true }
            ]
        });
    });
    
    
    public JsonResult List()
            {
                return Json(usrDB.GetAllUser(), JsonRequestBehavior.AllowGet);
            }

    Thanks

    Thursday, October 31, 2019 6:58 AM

All replies

  • User-719153870 posted

    Hi jsshivalik,

    Please modify your code like below:

    public JsonResult List()
            {
                return Json(new { data = usrDB.GetAllUser()}, JsonRequestBehavior.AllowGet);
            }

    You need to make this format so that the datatable can receive the data.

    Best Regard,

    Yang Shen

    Thursday, October 31, 2019 8:14 AM