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

What is the lightweight MVC paging control JPager.Net

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

What is the lightweight MVC paging control JPager.Net? in order to solve this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

JPager.Net MVC easy to use lightweight paging control, easy to use you can not imagine, lightweight you can not imagine.

JPager.Net MVC easy to use lightweight paging control, very easy to implement, very easy to use.

JPager.Net MVC easy to use lightweight paging control, the code is carefully deliberated, repeatedly suggested by many people to modify, and finally in use. It's very good to share with you. The source code is released altogether. Let's start with an effect picture:

JPager.Net MVC easy to use lightweight paging control JPager.Net .dll core code

PagerInBase.cs

Namespace JPager.Net {/ basic paging class / public class PagerInBase {/ current page / public int PageIndex {get; set;} / number of pages / public int PageSize {get; set;} / / skip the specified number of elements in the sequence public int Skip = > (PageIndex-1) * PageSize / request URL / public string RequetUrl = > System.Web.HttpContext.Current.Request.Url.OriginalString; / constructor initializes / public PagerInBase () {if (PageIndex = = 0) PageIndex = 1; if (PageSize = = 0) PageSize = 10;}

PagerResult.cs

Using System;using System.Collections.Generic;using System.Text;namespace JPager.Net {/ ULR assembly / internal static class Exts {public static string GetUrl (this string url, int curIndex, int reps) {return url.Replace ("pageindex=" + curIndex.ToString (), "pageindex=" + reps.ToString ()) }} / core paging code / public class PagerResult {public int Code {get; set;} public int Total {get; set;} public IEnumerable DataList {get; set;} public int PageSize {get; set;} public int PageIndex {get; set;} public string RequestUrl {get; set Default style: jpager / public string PagerHtml (string cssClass= "jpager") {if (PageIndex = = 0) PageIndex = 1; if (RequestUrl.IndexOf ("?", StringComparison.Ordinal) =-1) RequestUrl + = "? pageindex=1" Else if (RequestUrl.IndexOf ("& pageindex", StringComparison.Ordinal) =-1clients & RequestUrl.IndexOf ("? pageindex", StringComparison.Ordinal) =-1) RequestUrl + = "& pageindex=1"; var html = new StringBuilder (); html.AppendFormat ("", cssClass); var pageLen = Math.Ceiling ((double) Total / PageSize); html.AppendFormat ("Home", RequestUrl.GetUrl (PageIndex,1)) Html.AppendFormat ("previous page", RequestUrl.GetUrl (PageIndex, PageIndex < 2? 1: PageIndex-1); var si = PageIndex pageLen-1? PageLen: PageIndex + 1)); html.AppendFormat ("last page", Math.Abs (Total) t.Name.Contains (param.Name)) .ToList (): list.ToList (); / / paging data var data = query.Skip (param.Skip) .Take (param.PageSize); / / Total pages var count = query.Count Var res = new PagerResult {Code = 0, DataList = data, Total = count, PageSize = param.PageSize,PageIndex = param.PageIndex,RequestUrl = param.RequetUrl}; return View (res);} / / Test data public List PageContent () {var list = new List (); for (var t = 0; t < 10000) Tweak +) {list.Add (new User {Id = t, Name = "Joye.net" + t.ToString (), Age = t + 10, Score = t, Address = "http://yinrq.cnblogs.com/", AddTime = DateTime.Now});} return list;}}

Models folder to build User.cs and UserParams.cs

User.cs

Using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace JPager.Net.Web.Models {public class UserParams:JPager.Net.PagerInBase {public int Id {get; set;} public string Name {get; set;} public int? Age {get; set;} public int Score {get; set;} public string Address {get; set;} public DateTime AddTime {get; set;}

UserParams.cs

Using System;namespace JPager.Net.Web.Models {public class User {public int Id {get; set;} public string Name {get; set;} public int Age {get; set;} public int Score {get; set;} public string Address {get; set;} public DateTime AddTime {get; set;}

View display

@ model JPager.Net.PagerResult@ {ViewBag.Title = "Index" } JPager.Net MVC's lightweight paging control Name: Age: ID Name Age Score Address AddTime @ foreach (JPager.Net.Web.Models.User item in Model.DataList) {@ item.Id @ item.Name @ item.Age @ item.Score @ item.Address @ item.AddTime} @ Html.Raw (Model.PagerHtml ()) total @ Model.Total / / keep search criteria $(function ()) {$('# Name') .val ('@ ViewBag.SearchName') ('# Age') .val ('@ ViewBag.SearchAge');}

Github: https://github.com/decadestory/JPager.Net

This is the answer to the question about the lightweight MVC paging control JPager.Net. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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