您好,登錄后才能下訂單哦!
今天小編給大家分享一下MVC怎么使用MvcPager實現分頁效果的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
USE [StudentDB] GO /****** Object: Table [dbo].[UserInfo] Script Date: 07/27/2018 13:59:03 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[UserInfo]( [customerID] [int] IDENTITY(1,1) NOT NULL, [customerName] [varchar](50) NOT NULL, [PID] [varchar](50) NOT NULL, [telephone] [varchar](50) NOT NULL, [address] [varchar](20) NULL, PRIMARY KEY CLUSTERED ( [customerID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY], CONSTRAINT [UQ_PID] UNIQUE NONCLUSTERED ( [PID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO SET ANSI_PADDING OFF GO ALTER TABLE [dbo].[UserInfo] WITH CHECK ADD CONSTRAINT [CK_PID] CHECK ((len([PID])=(15) OR len([PID])=(18))) GO ALTER TABLE [dbo].[UserInfo] CHECK CONSTRAINT [CK_PID] GO ALTER TABLE [dbo].[UserInfo] WITH CHECK ADD CONSTRAINT [CK_telephone] CHECK ((len([telephone])=(11))) GO ALTER TABLE [dbo].[UserInfo] CHECK CONSTRAINT [CK_telephone] GO
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Web.Models { public class UserInfo { private int customerID; public int CustomerID { get { return customerID; } set { customerID = value; } } private string customerName; public string CustomerName { get { return customerName; } set { customerName = value; } } private string pid; public string Pid { get { return pid; } set { pid = value; } } private string telephone; public string Telephone { get { return telephone; } set { telephone = value; } } private string address; public string Address { get { return address; } set { address = value; } } } }
添加MvcPager.dll,并引用MvcPager的命名空間Webdiyer.WebControls.Mvc。
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Web.Models; using Webdiyer.WebControls.Mvc; namespace Web.Controllers { public class HomeController : Controller { // // GET: /Page/ //默認分頁 private const int defaultPageSize = 5; // public ActionResult Index(int? id) { using (DBDataContext db = new DBDataContext()) { IQueryable<UserInfo> p = from c in db.UserInfo select new UserInfo { CustomerID = c.customerID, CustomerName = c.customerName, Telephone = c.telephone, Pid = c.PID, Address = c.address }; PagedList<UserInfo> m = p.ToPagedList(id ?? 1, defaultPageSize); return View(m); } } } }
fo>>" %> <%@ Import Namespace="Web.Models" %> <%@ Import Namespace="Webdiyer.WebControls.Mvc" %> <!DOCTYPE html> <html> <head runat="server"> <meta name="viewport" content="width=device-width" /> <title>Index</title> <%--樣式表--%> <link href="../../Content/Site.css" rel="stylesheet" type="text/css" /> <script src="../../Scripts/jquery-1.8.2.min.js" type="text/javascript"></script> </head> <body> <div class="divfloat"> <div id="divpages"> <table> <tr> <th>編號 </th> <th>姓名 </th> <th>身份證號 </th> <th>電話號碼 </th> <th>地址 </th> </tr> <%foreach (UserInfo od in Model) { %> <tr> <td> <%=od.CustomerID.ToString() %> </td> <td> <%=od.CustomerName.ToString() %> </td> <td> <%=od.Pid.ToString() %> </td> <td> <%=od.Telephone.ToString() %> </td> <td> <%=od.Address.ToString() %> </td> </tr> <% } %> </table> new AjaxOptions() { UpdateTargetId = "divpages" })%>--%> <%=Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", CssClass = "pages", FirstPageText = "首頁", LastPageText = "末頁", PrevPageText = "上一頁", NextPageText = "下一頁", CurrentPagerItemWrapperFormatString = "<span class=\"cpb\">{0}</span>", ShowPageIndexBox = true, NumericPagerItemWrapperFormatString = "<span class=\"item\">{0}</span>", PageIndexBoxType = PageIndexBoxType.DropDownList, ShowGoButton = false,PageIndexBoxWrapperFormatString=" 轉到{0}",SeparatorHtml = "" })%> </div> </div> </body> </html>
以上就是“MVC怎么使用MvcPager實現分頁效果”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。