惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
Scott Helme
Scott Helme
NISL@THU
NISL@THU
Cisco Talos Blog
Cisco Talos Blog
C
Cybersecurity and Infrastructure Security Agency CISA
AWS News Blog
AWS News Blog
V
Vulnerabilities – Threatpost
J
Java Code Geeks
U
Unit 42
The GitHub Blog
The GitHub Blog
H
Help Net Security
T
Tenable Blog
aimingoo的专栏
aimingoo的专栏
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
L
Lohrmann on Cybersecurity
T
Threatpost
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
I
InfoQ
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog
L
LINUX DO - 最新话题
K
Kaspersky official blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Threat Research - Cisco Blogs
C
Check Point Blog
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
宝玉的分享
宝玉的分享
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
Y
Y Combinator Blog
N
News | PayPal Newsroom
M
MIT News - Artificial intelligence
Latest news
Latest news
H
Hacker News: Front Page
Blog — PlanetScale
Blog — PlanetScale
腾讯CDC
I
Intezer
爱范儿
爱范儿
F
Fortinet All Blogs
P
Palo Alto Networks Blog
C
CERT Recently Published Vulnerability Notes

博客园 - Jun1st

Application之间共享Master Page ASP.NET AJAX 4的Client-Side Template和DataView ASP.NET AJAX 4的Client-Side Template和DataView 体验ASP.NET4之ClientID 体验ASP.NET 4之URL Routing 使用Extension Methods来使IDataReader更加方便 Custom WCF Configuration File USE HttpRuntime.Cache OVER HttpContext.Current.Cache Make Asynchronous Calls from Page IIS and VS Embedded Local Web Server Integrate jQuery with ASP.NET Data Controls Tech-Ed 2008 上海 LINQ and Pipeline Pattern Why Would a .Net Programmer Learn Ruby On Rails(翻译) ASP.NET MVC之AJAX Asp.Net MVC---Walkthrough Asp.Net MVC 入门篇——Overview Asp.Net 2.0之SqlCacheDependency Security Basics and ASP.NET Support(翻译)
ASP.NET MVC的分页和导航
Jun1st · 2008-08-31 · via 博客园 - Jun1st

2008-08-31 21:56  Jun1st  阅读(6853)  评论()    收藏  举报

INTRODUCTION

更多的权利,就意味着更多的责任。在MVC中,我们几乎不再使用Drag and Drop来的各种控件,因此我们就不再受这些控件所提供的功能的限制,但是当然也就失去了这些控件所带来的好处和便利。比如GridView以及它所附带的分页功能。本文将利用LINQ的defered execution的特性来实现一个通用的分页和导航的PagedList。

CONTENT

为了是PagedList能有分页和导航的功能,因此我们需要知道总共有多少行数据,需要有多少个也需要显示。故可以定义这样一个接口

IPagedList

为了使这个通用的PagedList能真正的“通用”,就需要时使用泛型。.Net已经提供了很好了一个很好的基类,我们继承它就好了,同时实现IPagedList接口

PagedList1 PagedList2

对PagedList的构造函数中的最后一句代码稍作解释: index为从0开始计算的页数,可以为Null, pageSize 为每页显示的记录数。最后对ToList()的调用会使得这个IQueryable被执行,返回的List被加到这个PagedList中。

Application

PagedList基本完成了,该实际应用了。在页面文件中,根据PagedList的数据,对CSS做一些设置,就可以实现分页和导航的功能。

Pager

OK,We have done here.

这里没想到好方法把Controller的信息加进去,只好暂时hard code了

PS: This idea is generally from Rob Conery's StoreFront MVC serials