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

推荐订阅源

Y
Y Combinator Blog
GbyAI
GbyAI
爱范儿
爱范儿
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Check Point Blog
M
MIT News - Artificial intelligence
量子位
宝玉的分享
宝玉的分享
MongoDB | Blog
MongoDB | Blog
V
Visual Studio Blog
罗磊的独立博客
F
Fortinet All Blogs
美团技术团队
博客园_首页
博客园 - 【当耐特】
L
LangChain Blog
月光博客
月光博客
腾讯CDC
The Cloudflare Blog
D
Docker
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

博客园 - 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