它正确显示了页数,以及每页的所谓记录数为10.但是,当我单击页面x时,它不会重定向到下一页记录。
我在之前的项目中使用过这段代码,它运行得很好。有什么我可能错过的吗?
我的控制器:
public ActionResult Index(int? page)
{
try
{
int intPage = 1;
int intPageSize = 10;
int intTotalPageCount = 0;
List<Announcement> col_Announcement = new List<Announcement>();
int intSkip = (intPage - 1) * intPageSize;
intTotalPageCount = db.Announcements.Count();
var result = db.Announcements
.Take(intPageSize)
.ToList();
foreach (var item in result)
{
Announcement objAnnouncement = new Announcement();
objAnnouncement.AnnouncementDate = item.AnnouncementDate;
objAnnouncement.AnnouncementTitle = item.AnnouncementTitle;
objAnnouncement.AnnouncementBody = item.AnnouncementBody;
col_Announcement.Add(objAnnouncement);
}
// Set the number of pages
var _AnnouncementAsIPagedList =
new StaticPagedList<Announcement>
(
col_Announcement, intPage, intPageSize, intTotalPageCount
);
return View(_AnnouncementAsIPagedList);
}
catch (Exception ex)
{
ModelState.AddModelError(string.Empty, "Error: " + ex);
List<Announcement> col_Announcement = new List<Announcement>();
return View(col_Announcement.ToPagedList(1, 25));
}
}
我的观点:
@model PagedList.IPagedList<Test.Models.Announcement>
@using PagedList.Mvc;
<div class="jumbotron">
<h2>Announcements</h2>
<table class="table">
<tr>
<th>
Date Posted
</th>
<th>
Title
</th>
<th>
Body
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.AnnouncementDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.AnnouncementTitle)
</td>
<td>
@Html.DisplayFor(modelItem => item.AnnouncementBody)
</td>
</tr>
}
</table>
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index", new {page}))
</div>
答案 0 :(得分:0)
在拍摄记录之前,您需要跳过一些记录
<div class="container">
<div class="row">
<div class="col-xs-12 d-flex justify-content-center align-items-center" style="height:80px">
<a href="ghfhg"><i class="fa fa-calendar" style="color: rgb(72, 168, 237); font-size: 32px; line-height: 80px; text-align: center; width: 80px; height: 80px; display: inline-block; overflow: hidden; border-radius: 50%; background-color: rgb(224, 231, 237); margin-right: 5px;"></i></a>
sdsad
</div>
</div>
</div>