mvc框架实现简单分页
1.效果图通过a标签的href简单实现静态的页面上下页的切换
2.view视图代码
<nav><ul class=\"pagination\"><li class=\"page-item\"><a href=\"/Role/Index?pageIndex=1\" class=\"page-link\">首页</a></li><li class=\"page-item\"><a href=\"/Role/Index?pageIndex=1\" class=\"page-link\">上一页</a></li><li class=\"page-item\"><a href=\"/Role/Index?pageIndex=2\" class=\"page-link\">下一页</a></li><li class=\"page-item\"><a href=\"/Role/Index?pageIndex=3\" class=\"page-link\">末页</a></li><li><input type=\"button\" value=\"GO\" onclick=\"page(2)\" class=\"btn-primary \" /></li></ul></nav>
3.控制器代码
public ActionResult Index(string Name, int PageIndex = 2, int PageSize = 4){var roles = dt.Roles.Where(p => Name == null || p.Name.Contains(Name)).OrderBy(P => P.ID).Skip(PageSize * (PageIndex - 1)).Take(PageSize).ToList();return View(roles);}