我正在使用分页来列出数据库中的候选人。我在一页中列出了 12 条记录。如果只有 1 页要列出详细信息,我不希望显示分页。请帮帮我。以下是我的代码。控制器:
[HttpGet]
public ActionResult Index(int? page, int? filter)
{
ViewBag.statusName = db.CandidateStatuses.ToList();
int pageSize = 12;
int pageNumber = (page ?? 1);
var candidates = new List<Candidate>();
if (filter != null)
{
ViewBag.Filter = filter;
candidates = db.Candidates.Where(m => m.CandidateStatusID == filter).OrderByDescending(m => m.CandidateID).ToList();
}
else
{
candidates = db.Candidates.OrderByDescending(m => m.CandidateID).ToList();
}
return View(candidates.ToPagedList(pageNumber, pageSize));
}
看法:
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index", new { page, filter = ViewBag.Filter }))
我只在我的视图中显示了分页部分的代码。请帮帮我。