MVC三种分页方法
View部分:
@using WebApplication1.Models;分页方法1引包
@*@using PagedList.Mvc;
@using WebApplication1.Models;
@model PagedList.IPagedList<WebApplication1.Models.t_users>*@
@*分页方法1*@
@Html.Pager(Model, new PagerOptions
{
Id = "htmlPager",
PageIndexParameterName = "pageIndex",
FirstPageText = "首页",
PrevPageText = "上一页",
NextPageText = "下一页",
LastPageText = "尾页",
CssClass = "pagination pagination-sm",
CurrentPagerItemTemplate = "<li class=\"active\">" +
"<a href=\"#\">{0}</a></li>",
DisabledPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>",
PagerItemTemplate = "<li>{0}</li>"
})
@*分页方法2*@
@*@Html.PagedListPager(Model, page => Url.Action("UserList", new { page }))*@
Controller部分:
//第三方插件分页1:using Webdiyer.WebControls.Mvc;
public ActionResult UserList(int pageIndex = 1)
{
List<t_users> userListAll = education.t_users.ToList();
userListAll = userListAll.ToPagedList(pageIndex, 5);
return View(userListAll);
}
//第三方插件分页2:using PagedList;
//public ActionResult UserList(int page = 1)
//{
// List<t_users> userListAll = education.t_users.ToList();
// return View(userListAll.ToPagedList(page, 5));
//}
//用户详情
public ActionResult DetailsUser(int id)
{
var users = education.t_users.Where<t_users>(u => u.data_state == 0 && u.us_sid == id).FirstOrDefault();
return View(users);
}