0

Im Getting Error as http://localhost:47237/Home_Business/Home_Business/GetData?draw=1&columns%5B0%5D%5Bdata%5D=Emp_Id&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=true&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B1%5D%5Bdata%5D=EmpName&columns%5B1%5D%5Bname%5D=&columns%5B1%5D%5Bsearchable%5D=true&columns%5B1%5D%5Borderable%5D=true&columns%5B1%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B1%5D%5Bsearch%5D%5Bregex%5D=false&columns%5B2%5D%5Bdata%5D=Email&columns%5B2%5D%5Bname%5D=&columns%5B2%5D%5Bsearchable%5D=true&columns%5B2%5D%5Borderable%5D=true&columns%5B2%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B2%5D%5Bsearch%5D%5Bregex%5D=false&order%5B0%5D%5Bcolumn%5D=0&order%5B0%5D%5Bdir%5D=asc&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1512374513133

here im trying to loading data in jqueryData Table insted of showing data in tabler Format its showing in Json Like

{"iTotalRecords":12,"aaData":[{"Emp_Id":101,"EmpName":"Hussain","Email":"[email protected]","Psw":null,"Cnt_Id":0,"Cnt_Name":"India","Sts_Id":0,"Sts_Name":"Telangana","City_Id":0,"City_Name":"Hyd","dept_ID":null,"Date":"\/Date(1420050600000)\/","sal":15000,"Gen_Id":null,"Gen_Name":null}]}

Mvc code

 public ActionResult Index()
        {
            var x = ObjRepo.GetEmployees(1);
            int size =ObjRepo.CountEmployee();
           return Json(new { iTotalRecords = size, aaData }, JsonRequestBehavior.AllowGet);

        }

Jquery

 $(document).ready(function () {
        $('#table_id').dataTable({
//Here i Hotcoded my data Even imm not dusplay data
            "iTotalRecords":12,"aaData":[{"Emp_Id":101,"EmpName":"Hussain","Email":"[email protected]"
            }],
            "processing": true,
            "serverSide": true,
            "Columns": [
                         { 'data': 'Emp_Id' },
                         { 'data': 'EmpName' },
                         ],
        });
    })
1
  • columns should be small letter C Commented Dec 7, 2017 at 7:53

1 Answer 1

1

you can do something like this inside a function or in document ready..

     $.ajax({
        type: 'GET',
        url: '@Url.Action("GetEmployees", "ControllerName")',
        cache: false,
        success: function (result) {
            $("#table_id").DataTable({
                destroy: true,
                data: result,
                columns: [
                    { data: 'employee_id' },
                    { data: 'employee_name' }
                ]
            });
        }
    });

then you need to have html table with thead on your #table_id

Controller:

[HttpGet]
public ActionResult GetEmployees()
{
     var x = ObjRepo.GetEmployees(1);
     int size =ObjRepo.CountEmployee();
     return Json(new { iTotalRecords = size, aaData }, JsonRequestBehavior.AllowGet);
}
Sign up to request clarification or add additional context in comments.

3 Comments

Jquery Datatable can load datas from api by itself. It's not adequate to use jquery ajax before datable init
Im getting data as Object--->ObjRepoentity----->data:Array(5):0:{Emp_Id: 101, EmpName: null, Email: "[email protected]", Psw: null, Cnt_Id: 0
when i try to access as 'data:'Emp_Id' its not working

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.