估计是因为水平原因,之前看别人写的用pagedList分页,老是云里雾里的。下面把自己写的整理一下放在上面。这里的List为对应页面展示的内容。不用查询所有。

Action:

public ActionResult Index(string sortOrder, string currentFilter, string searchString, int? page)

{

ViewBag.CurrentSort = sortOrder??"sortOrder";

ViewBag.CurrentFilter = currentFilter ?? "currentFilter";

List<Student> students = new List<Student>();

for (int i = 0; i < 10; i++)

{

students.Add(

new Student()

{

SchoolId = i,

Name = "Name" + i,

Grad = "Grad" + i,

});

}

//public StaticPagedList(IEnumerable<T> subset, int pageNumber, int pageSize, int totalItemCount);

int pageNumber = (page ?? 1);

var firstPage = new StaticPagedList<Student>(students, pageNumber, 10, 100);

return View(firstPage);

}

view:

@model PagedList.IPagedList<PageListDemo.ModelDisplay.Student>

@using PagedList.Mvc; <link href="~/Content/PagedList.css" rel="stylesheet" type="text/css" />

@{     ViewBag.Title = "主页"; }

<table class="table">

<tr>

<th>StudentId</th>

<th>Name</th>

<th>Grad </th>

<th></th>     </tr>

@foreach (var item in Model) {

<tr>         <td>             @Html.DisplayFor(modelItem => item.SchoolId)         </td>         <td>             @Html.DisplayFor(modelItem => item.Name)         </td>         <td>             @Html.DisplayFor(modelItem => item.Grad)         </td>     </tr> } </table> <br /> Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount <br /> Results:@Model.TotalItemCount

@Html.PagedListPager(Model, page => Url.Action("Index",     new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }),     new PagedListRenderOptions(){         MaximumPageNumbersToDisplay=5,         DisplayLinkToIndividualPages=true,         LinkToFirstPageFormat="首页",         LinkToLastPageFormat="尾页",         LinkToNextPageFormat="下一页",         LinkToPreviousPageFormat="上一页",         DisplayEllipsesWhenNotShowingAllPageNumbers=false,                })

StaticPagedList的更多相关文章

  1. PagedList.MVC分页

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  2. ASP.NET MVC之PagedList使用

    ASP.NET MVC之PagedList使用 ---由于最近项目中用到了分页这里也来记录一下,一方面给自己一个记录,另一方面给后来者一些帮助! 一.首先大家先来看一下效果

  3. ASP.NET MVC利用PagedList分页(二)PagedList+Ajax+JsRender

    (原文) 昨天在ASP.NET MVC利用PagedList分页(一)的 最后一节提到,一个好的用户体验绝对不可能是点击下一页后刷新页面,所以今天来说说利用Ajax+PagedList实现无刷新(个人 ...

  4. ABP入门系列(7)——分页实现

    ABP入门系列目录--学习Abp框架之实操演练 完成了任务清单的增删改查,咱们来讲一讲必不可少的的分页功能. 首先很庆幸ABP已经帮我们封装了分页实现,实在是贴心啊. 来来来,这一节咱们就来捋一捋如何 ...

  5. MVC无刷新查询,PagedList分页控件使用,导出Excel

    使用MVC开发也有一段时间了,总结下无刷新部分视图的使用.PagedList分页控件的使用. @using PagedList @model StaticPagedList<T> < ...

  6. MVC+Bootstrap+Drapper使用PagedList.Mvc支持多查询条件分页

    前几天做一个小小小项目,使用了MVC+Bootstrap,以前做分页都是异步加载Mvc部分视图的方式,因为这个是小项目,就随便一点.一般的列表页面,少不了有查询条件,下面分享下Drapper+Page ...

  7. 一步一步创建ASP.NET MVC5程序[Repository+Autofac+Automapper+SqlSugar](十一)

    前言 小伙伴们, 大家好,我是Rector. 最近Rector忙于换工作,没有太多时间来更新我们的ASP.NET MVC 5系列文章 [一步一步创建ASP.NET MVC5程序Repository+A ...

  8. VS2017 ASP.NET MVC 5.0 开部署问题汇总

    1[SqlException (0x80131904): 拒绝了对对象 '****' (数据库 '***',架构 'dbo')的 EXECUTE 权限.] “/”应用程序中的服务器错误. SQL 20 ...

  9. ASP.NET MVC利用PagedList分页(一)

    前几天看见博客园上有人写ASP.NET MVC的分页思想,这让我不禁想起了PagedList.PagedList是NuGet上提供的一个分页的类库,能对任何IEnumerable<T>进行 ...

随机推荐

  1. PSP(11.2~11.9)

    5号 类别c 内容c 开始时间s 结束e 中断I 净时间T GUI 学习QT视频 9:00 10:10 0m 70m 复习 软件工程 10:10 11:10 10 50m 复习 软件工程 14:20 ...

  2. G不可失

    html和css部分和引用的库 <!DOCTYPE html><html lang="en"><head> <meta charset=& ...

  3. Python多线程join的用法

    import threading, time def Myjoin(): print 'hello world!' time.sleep(1) for i in range(5): t=threadi ...

  4. 使用智能指针来管理对象 (基于RAII)

    ////一个简单的防止内存泄露的例子//void test() { //使用RAII的特性管理资源 //当智能指针unique_ptr被销毁时,它指向的对象也将被销毁 //这里test函数返回后 p将 ...

  5. 使用VS2013逆向生成UML类图

    引自http://blog.csdn.net/funnyfu0101/article/details/7705173 首先.打开工程,[体系结构]->[新建关系图] 生成一个类图 然后[体系结构 ...

  6. Oracle数据库BLOB字段的存取

    述]     Oracle的Blob字段比较特殊,他比long字段的性能要好很多,可以用来保存例如图片之类的二进制数据. 写入Blob字段和写入其它类型字段的方式非常不同,因为Blob自身有一个cur ...

  7. nginx学习笔记

    我的工作环境是 Debian . 在 Debian 上安装 ngingx 和其他 linux 安装基本相同. 在配置 hello world 之前,没有头绪,看了很多资料.最后 "https ...

  8. 单片网络接口芯片W5100的原理与应用

    随着计算机网络技术的发展,作为全球最大计算机网络——I n t e r ac t已成为当今信息社会重要的基础信息设施.在工业测控.智能仪器.智能家庭等领域,大量应用嵌入式设备接人 I n t e r ...

  9. C++ 随机数

    #include <iostream> #include <stdlib.h> #include <time.h> #define random(a,b) (ran ...

  10. MySQL数据库(表)的导入导出(备份和还原)

    一)在同一个数据库服务器上面进行数据表间的数据导入导出: 1. 如果表tb1和tb2的结构是完全一样的,则使用以下的命令就可以将表tb1中的数据导入到表tb2中: insert into db2.tb ...