Asp.net mvc 数据表与MVC
我使用datatables jquery插件在服务器端进行分页时遇到问题。网格底部的分页控件显示 显示从7253个总条目中筛选出的10个条目中的1到10个条目 但我不会过滤任何记录。如果单击下一个或上一个链接,则不会将ajax请求发送回服务器。我希望看到 显示7253项中的1至10项 控制器代码Asp.net mvc 数据表与MVC,asp.net-mvc,datatables,jquery-datatables,Asp.net Mvc,Datatables,Jquery Datatables,我使用datatables jquery插件在服务器端进行分页时遇到问题。网格底部的分页控件显示 显示从7253个总条目中筛选出的10个条目中的1到10个条目 但我不会过滤任何记录。如果单击下一个或上一个链接,则不会将ajax请求发送回服务器。我希望看到 显示7253项中的1至10项 控制器代码 public ActionResult GetDataTable(DataTableParamModel param) { var allhotelscount = d
public ActionResult GetDataTable(DataTableParamModel param)
{
var allhotelscount = db.Businesses.OfType<Hotel>().Count();
var filteredhotels = db.Businesses.OfType<Hotel>().OrderBy(h => h.Name);
IEnumerable<DataTableHotel> displayedhotels = from c in filteredhotels
.Skip(param.iDisplayStart).Take(param.iDisplayLength)
select new DataTableHotel
{
Id = c.Id,
Name = c.Name,
CityState = c.PhysicalCity + ", " + c.PhysicalState,
PhoneNumber = c.PhoneNumber,
PrimaryContact = c.PrimaryContact.FirstName + " " + c.PrimaryContact.LastName,
PrimaryContactPhone = c.PrimaryContact.OfficePhone,
PrimaryContactEmail = c.PrimaryContact.EmailAddress,
};
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = allhotelscount,
iTotalDisplayRecords = displayedhotels.Count(),
aaData = displayedhotels
},
JsonRequestBehavior.AllowGet);
}
查看代码:
<table id="myDataTable" class="display">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>City, State</th>
<th>Phone</th>
<th>Contact</th>
<th>Phone</th>
<th>Email</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function () {
$('#myDataTable').dataTable({
"bServerSide": true,
"sAjaxSource": "/Hotel/GetDataTable",
"bProcessing": true,
"aoColumns": [
{ "mData": "Id" },
{ "mData": "Name" },
{ "mData": "CityState" },
{ "mData": "PhoneNumber" },
{ "mData": "PrimaryContact" },
{ "mData": "PrimaryContactPhone" },
{ "mData": "PrimaryContactEmail" },
]
});
});
您向iTotalDisplayRecords传递了错误的值,请参阅以下代码:
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = allhotelscount,
iTotalDisplayRecords = allhotelscount,
aaData = displayedhotels
},
JsonRequestBehavior.AllowGet);
哇,我看了这么久。谢谢你的关注