1

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.

4
  • What is your question? What was the contents of this warning message box? Commented Mar 31, 2011 at 9:28
  • This is the error message DataTables warning (tableid="employeeviews"): Added data (size undefined) does not match known number of columns(5) Commented Mar 31, 2011 at 10:33
  • I want to use the ajax with the datatable in the asp.net mvc for handling the display of the data in the form of tables with paging, sorting etc Commented Mar 31, 2011 at 10:35
  • atlast i solved the sorting issues, but still struggling with the paging issues. i get the page no as 1 and not as 1,2. i.e. i have 15 records and have displayed 10 records. in the pagination, i have 1 only actually i should have 2. If i get this, all my datatables problems are going to end.. any suggestions on this point? Commented Mar 31, 2011 at 14:51

1 Answer 1

0

Sorted out by myself and no need for another answer.

Sign up to request clarification or add additional context in comments.

Comments

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.