Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use MvcPager to achieve paging effect in MVC

Shulou Source: shulou.com Published: 2022-06-01 03:18:48 10月04日 Update

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.

Tags: Knowledge article effect content different big number address most name that is controller data database more telephone phone number knowledge point space industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Linux MariaDB Shulou Technology Shulou Tech Info