本文实例为大家分享了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>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。