简体   繁体   中英

using the datatables jquery plugin with asp.net mvc2

I started to use the jquery datatables plugin for asp.net mvc2. I have the following code in the index.aspx page of the view.

 $(document).ready(function () {
        $('#employeeviews').dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "/Employee/listEmployees",
            "fnServerData": function (sSource, aoData, fnCallback) {
                alert("aodata is : "+aoData);
                alert("as source is : "+sSource);
                $.ajax({
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": aoData,
                    "success": fnCallback
                });
            }
        });
    });

Now that I have written all these, in the controller, i have an action that returns the partialview.

  [HttpPost]
    //public ActionResult listEmployees()
    public JsonResult listEmployees()
    {
        if (Request.IsAjaxRequest())
        {
            Models.EmployeeModel empModel = new Models.EmployeeModel();
            //return Json(PartialView("EmployeeList", empModel.getAllEmployees()), JsonRequestBehavior.AllowGet);
            //return Json(empModel.getAllEmployees());

            return Json(new
            {
                iTotalRecords = 11,
                iTotalDisplayRecords = 3,
                aaData = empModel.getAllEmployees()
            }, JsonRequestBehavior.AllowGet);
        }
        else
            return null;
    }

Now what i get is warning messagebox from jquery. I also tried to use the partial view method to return the partial view.

But I have a problem in this, where exactly can i get the output of the ajax response in the js file so that i can set the output accordingly in the view page, as it is not clear in this process. Also i am planning to handle the ajax and paging requests. When i am done with this, i can move to the other parts.

I am also going to test this with the use of the MVCContrib grid control so that the functionality is clear for me.

由我自己整理,不需要其他答案。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM