Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use MvcPager to achieve paging effect in MVC

2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, the editor will share with you the relevant knowledge about how MVC uses MvcPager to achieve paging effect. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

1. Database table USE [StudentDB] GO / * Object: Table [dbo]. [UserInfo] Script Date: 07 Accord 2018 13:59:03 * / SET ANSI_NULLS ONGO SET QUOTED_IDENTIFIER ONGO SET ANSI_PADDING ONGO CREATE TABLE [dbo]. [UserInfo] ([customerID] [int] IDENTITY (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 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 II, Establish Linq

Create UserInfousing 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 in Model } 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;} IV. Create a Home controller in Controllers

Add MvcPager.dll and reference the namespace Webdiyer.WebControls.Mvc of MvcPager.

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/ default paging private const int defaultPageSize = 5; / / public ActionResult Index (int? Id) {using (DBDataContext db = new DBDataContext ()) {IQueryable 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 m = p.ToPagedList (id? 1, defaultPageSize) Return View (m) 5. Add view Indexfo > > "% > Index number, name, ID number Telephone number and address New AjaxOptions () {UpdateTargetId = "divpages"})% >--% > above is all the content of the article "how MVC uses MvcPager to achieve paging effect" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report