我开始使用asp.net mvc2的jquery datatables插件。我在视图的index.aspx页面中有以下代码。
$(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
});
}
});
});
现在我已经写了所有这些,在控制器中,我有一个返回部分视图的动作。
[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;
}
现在我得到的是来自jquery的警告messagebox。我还尝试使用局部视图方法返回局部视图。
但是我有一个问题,我可以在js文件中获得ajax响应的输出,这样我就可以在视图页面中相应地设置输出,因为在此过程中不清楚。我还计划处理ajax和分页请求。完成后,我可以转到其他部分。
我也将使用MVCContrib网格控件对此进行测试,以便我能够清楚地了解这一功能。
答案 0 :(得分:0)
由我自己排序,不需要另外的答案。