Jpager.net MVC easy to use lightweight paging control, easy to use you can not imagine, lightweight to you can not imagine.
Jpager.net MVC's lightweight paging control is very simple and easy to use.
Jpager.net MVC easy to use the lightweight paging control, the code carefully refined, after repeated suggestions by many people to modify, the final form used. Very useful to share with you. The source code is put out altogether. First Effect chart:
Jpager.net MVC Easy Lightweight Paging control jpager.net. DLL Core Code
PagerInBase.cs
Namespace Jpager.net
{
///<summary>
///Paging base class
///</summary> public
class Pagerinbase
{
///<summary>
///current page
///</summary> public
int PageIndex {get; set;}
///<summary>
///page
///</summary> public
int PageSize {get; set;}
Skips the specified number of elements in the sequence public
int skip => (PageIndex-1) * PageSize;
<summary>
///Request URL
///</summary> public
string Requeturl => System.Web.HttpContext.Current.Request.Url.OriginalString;
<summary>
///Constructor initializes
///</summary> public
pagerinbase ()
{
if () for the current page and number of pages PageIndex = = 0) PageIndex = 1;
if (PageSize = = 0) PageSize = Ten}}}
PagerResult.cs
Using System;
Using System.Collections.Generic;
Using System.Text; namespace Jpager.net {///<summary>///ULR Assembly///</summary> Internal static class Exts {Publi C Static String GetUrl (this string url, int curindex, int reps) {return URL. Replace ("pageindex=" + curindex.tostring (), "pageindex=" + Reps.
ToString ()); }///<summary>///paging core code///</summary>///<typeparam name= "T" ></typeparam> Publ
IC class Pagerresult<t> {public int Code {get; set;}
public int total {get; set;}
Public ienumerable<t> DataList {get; set;}
public int PageSize {get; set;}
public int PageIndex {get; set;}
public string Requesturl {get; set;} <summary>///pagination page number HTML///</summary>///<param name= "CssClass" > Default style: JPAGER</PARAM&G
T
<returns></returns> 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) = = -1&& Requesturl.indexof ("? Pageind
Ex ", stringcomparison.ordinal) = = 1) Requesturl + =" &pageindex=1 ";
var html = new StringBuilder (); Html.
AppendFormat ("<span class= ' {0} ' >", CssClass);
var Pagelen = math.ceiling ((double) total/pagesize); Html.
AppendFormat ("<a href= ' {0} ' > Home </a>", Requesturl.geturl (pageindex,1)); Html.
AppendFormat ("<a href= ' {0} ' > Prev </a>", Requesturl.geturl (PageIndex, PageIndex < 2? 1:pageindex-1)); var si = PageIndex <= 6?
1:pageindex-5;
var ei = si + 9; while (Si <= pagelen && si <= ei) html. AppendFormat (si = = PageIndex?
"<a style= ' color:black;border:none; ' href= ' {0} ' > {1} </a>" : "<a href= ' {0} ' > {1} </a>", Requesturl.geturl (PageIndex, si), si++); Html. AppendFormat ("<a href= ' {0} ' > next page </a>", Requesturl.geturl (PageIndex, (int) (PageIndex > pageLen-1? pagele
N:pageindex + 1))); Html. AppendFormat ("<a href= ' {0} ' > Last </a>", Math.Abs (total) <= 0?
Requesturl.geturl (PageIndex, 1): Requesturl.geturl (PageIndex, (int) pagelen)); Html.
Append (@ "</span>"); return HTML.
ToString ();
}
}
}
How to use:
HomeController.cs
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using SYSTEM.WEB.MVC;
Using Jpager.net;
Using JPager.Net.Web.Models; Namespace JPager.Net.Web.Controllers {public class Homecontroller:controller {public ActionResult Index (userpa Rams param) {//The number of bars displayed per page defaults to//param.
PageSize = 10; Save search condition Viewbag.searchname = param.
Name; Viewbag.searchage = param.
Age;
Gets the data set var list = PageContent (); Retrieves var query = param based on criteria.
Name!=null? List. Where (T=>t.name.contains (param). Name)). ToList (): list.
ToList (); Page-Data var = query. Skip (param. SKIP). Take (param.
PageSize); Total pages var count = query.
Count; var res = new Pagerresult<user> {Code = 0, DataList = data, total = count, PageSize = param. Pagesize,pageindex = param. Pageindex,requesturl = param.
Requeturl};
Return View (RES); }//test data public list&Lt
User> PageContent () {var list = new list<user> (); for (var t = 0; t < 10000; t++) {list. ADD (new User {Id = t, Name = "joye.net" +t.tostring (), age = t + Score
= T, address = "http://yinrq.cnblogs.com/", Addtime = DateTime.Now});
} return list;
}
}
}
Models folders built 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<jpager.net.web.models.user> @{viewbag.title = "Index";}
Github:https://github.com/decadestory/jpager.net