MVC MvcPager分页
首先添加引用下载 MvcPager
别忘了再Web.config文件中添加引用
(1)标准URL分页
Controllers :
View Code
public ActionResult Index(int? id) { using (var db = new MvcPagerSampleDataContext()) { PagedList<Order> orders = db.Orders.ToPagedList(id ?? 1, 20); return View(orders); } }
view :
View Code
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PagedList<Order>>" %> <%@ Import Namespace="Webdiyer.WebControls.Mvc"%> <%@ Import Namespace="MvcPagerSample.Models"%> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> MvcPager 标准Url分页示例 </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h1>MvcPager 标准Url分页示例</h1> <table width="98%"> <tr><th>订单编号</th><th>订单日期</th><th>顾客编号</th><th>收货地址</th></tr> <%foreach(Order od in Model) { %> <tr><td><%=od.OrderID %></td><td><%=od.OrderDate.ToString() %></td> <td><%=od.CustomerID %></td><td><%=od.ShipAddress %></td></tr> <% } %> </table> <%=Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id" })%> </asp:Content>