开发者

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 t开发者_如何学Gohis, 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.


Sorted out by myself and no need for another answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜