MVC使用MvcPager实现分页效果

本文实例为大家分享了MVC使用MvcPager实现分页效果的具体代码,供大家参考,具体内容如下
一、数据库表

USE [StudentDB]GO /****** Object:Table [dbo].[UserInfo]Script Date: 07/27/2018 13:59:03 ******/SET ANSI_NULLS ONGO SET QUOTED_IDENTIFIER ONGO SET ANSI_PADDING ONGO 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 OFFGO ALTER TABLE [dbo].[UserInfo]WITH CHECK ADDCONSTRAINT [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 ADDCONSTRAINT [CK_telephone] CHECK((len([telephone])=(11)))GO ALTER TABLE [dbo].[UserInfo] CHECK CONSTRAINT [CK_telephone]GO

二、建立Linq MVC使用MvcPager实现分页效果
文章图片

MVC使用MvcPager实现分页效果
文章图片

三、在Model创建UserInfo
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; }}}}

四、在Controllers创建Home控制器 添加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 p = from c in db.UserInfoselect new UserInfo { CustomerID = c.customerID, CustomerName = c.customerName, Telephone = c.telephone, Pid = c.PID, Address = c.address }; PagedList m = p.ToPagedList(id ?? 1, defaultPageSize); return View(m); }} }}

五、添加视图Index
fo>>" %> Index - 锐客网
编号姓名身份证号电话号码地址
new AjaxOptions() { UpdateTargetId = "divpages" })%>--%>

【MVC使用MvcPager实现分页效果】以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

    推荐阅读