@using PagedList;
@using PagedList.Mvc;
@model IPagedList<eSchoolSemi.Web.Areas.NastavnikModul.ViewModels.OdrzaniCasIndexVM>
@{
ViewData["Title"] = "Index";
Layout = "~/Areas/NastavnikModul/Views/Shared/_Layout.cshtml";
}
<h1>Casovi</h1>
<table class="table table-bordered">
<thead>
<tr>
<th>Subject</th>
<th>Class Name</th>
<th>Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@item.Subject</td>
<td>@item.ClassName</td>
<td>@item.Date</td>
<td>
<a class="btn btn-primary" href="/TeacherModule/HeldClasses/Edit?HeldClassID=@item.HeldClassID&ClassID=@item.ClassID&ClassName=@item.ClassName&Subject=@item.Subject">Edit</a>
<a class="btn btn-primary" href="/TeacherModule/HeldClasses/Delete?HeldClassID=@item.HeldClassID&ClassID=@item.ClassID">Delete</a>
</td>
</tr>
}
</tbody>
</table>
这里的问题是,当我添加
@Html.PagedListPager
出现错误。即使模型类型为IPagedList。我一直在这里寻找答案,其中大多数正在将IEnumerable更改为IPagedList,但就我而言,它一直都是IPagedList。
在我的控制器中,
return View(VM.ToPagedList(page?? 1, 5));
所以肯定是返回分页列表...我不知道我在这里做错了什么。
编辑:有关更多信息,请从控制器中添加索引功能
public IActionResult Index(int? page)
{
UserData _User = HttpContext.GetLoggedUser();
var Teacher = _db.Teacher.First(x => x.UserID == _User.LoggedUserID);
var query = from O in _db.HeldClass
join OD in _db.Class on O.ClassID equals OD.ClassID
join NP in _db.Sylabus on OD.SylabusID equals NP.SylabusID
join NPP in _db.SylabusSubjects on NP.SylabusSubjectID equals NPP.SylabusSubjectID
join P in _db.Subject on NPP.SubjectID equals P.SubjectID
join A in _db.Employment on NPP.SylabusSubjectID equals A.SylabusSubjectID
where A.TeacherID == Nastavnik.UserID
orderby O.Date descending
select new { P.Name, OD.Symbol, O.ClassID, O.HeldClassID, O.Date };
List<HeldClassIndexVM> VM = query.Select(x => new HeldClassIndexVM
{
ClassID = x.ClassID,
Date = x.Date,
HeldClassID = x.HeldClassID,
Subject = x.Name,
Symbol = x.Symbol
}).ToList();
return View(VM.ToPagedList(page?? 1, 5));
}