请帮忙
我正在使用 datatables jQuery Plugin 来显示一个表格,它显示所有条目而没有分页的问题。请帮助这是我的 index.cshtml
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>jQuery DataTables/ASP.NET MVC Integration</title>
<link href="~/Content/dataTables/demo_table.css"
rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="~/Scripts/jQuery.dataTables.min.js"
type="text/javascript"></script>
<script src="~/Scripts/index.js"
type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="demo">
<h2>Index</h2>
<table id="myDataTable" class="display">
<thead>
<tr>
<th>firstName</th>
<th>lastName</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>
这是我的控制器
public ActionResult AjaxHandler(JQueryDataTableParamModel param)
{
List<string[]> myList = new List<string[]>();
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
myList.Add(new[] { "bla", "blabla" });
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = myList.Count(),
iTotalDisplayRecords = myList.Count(),
aaData = myList
},
JsonRequestBehavior.AllowGet);
}
这是js文件
$(document).ready(function () {
var oTable = $('#myDataTable').dataTable({
"bServerSide": true,
"sAjaxSource": "Home/AjaxHandler",
"bProcessing": true,
"aoColumns": [
{ "sName": "firstName" },
{ "sName": "LastName" },
]
});
});
即使我尝试修改这个 js 文件,但仍然显示所有数据而没有分页
$(文档).ready(函数 () {
var oTable = $('#myDataTable').dataTable({
"bServerSide": true,
"sAjaxSource": "Home/AjaxHandler",
"bProcessing": true,
"aLengthMenu": [[25, 50, 75, -1], [25, 50, 75, "All"]],
"iDisplayLength": 25,
"aoColumns": [
{ "sName": "firstName" },
{ "sName": "LastName" },
]
});
});