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

推荐订阅源

H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
爱范儿
爱范儿
L
LangChain Blog
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
G
Google Developers Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - TT.Net

netcore使用IdentityServer在nginx下502错误的解决 更新到.netcore3.0后找不到dotnet-ef的解决办法 openssh-win64 on windows2016 ssh pub key config 405 Method Not Allowed error with PUT or DELETE Request on IIS Server minikube windows hyperx填坑记 angular当router使用userhash:false时路由404问题 内网gitlab11.2升级至11.4.5 Angular7上手体验 - TT.Net - 博客园 ASP.NET MVC 3 Preview 1 发布 asp.net mvc + JqueryValidate(二) Asp.net MVC +JQueryValidation + AjaxForm 自己用的一个ASP.Net MVC分页拿出来分享下 Microsoft MVC Preview 2 ActionFilterAttribute实际开发中的应用 [转]A Templated ASP.NET RSS Feed Reader Control ASP.NET MVC preview 1升级到ASP.NET MVC preview 2的一些更改 Microsoft ASP.NET MVC中Membership登陆的实现 今天遇到一个非常奇怪的问题 评:C#中一个字符串重复N倍的方法 常用的匹配正则表达式和实例
基于IPagedList 的 Asp.Net MVC 分页
TT.Net · 2010-05-11 · via 博客园 - TT.Net

去年写过一篇MVC分页的

自己用的一个ASP.Net MVC分页拿出来分享下

现在发一个改进版

里面用到的IPagedList我自己也记不清是从哪里COPY来的了。呵呵

这里我就不把IPagedList的代码贴出来了,要使的下载DEMO自己拿吧。

image

后台对数据的分页

public ActionResult Index([DefaultValue(1)]int p,[DefaultValue(10)]int pagesize)
        {
            var model = Database.List.OrderByDescending(z=>z.Id).ToPagedList(p-1,pagesize);
            return View("Index",model);
        }

个人最近比较喜欢使用DefaultValue

当然也可以写成

public ActionResult Index(int? p,int? pagesize)
        {
            p = p ?? 1;
            pagesize = pagesize ?? 10;
            var model = Database.List.OrderByDescending(z=>z.Id).ToPagedList(p-1,pagesize);
            return View("Index",model);
        }

这里ToPagedList 这个扩展方法里第一个参数是index

image

懒得去改成page了,所以就用了 p-1

前台中调用

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage<MvcDemo.IPagedList<MyModel>>" %>
    <%= Html.PagerBar(ViewData.Model) %>
    <table>
        <thead>
        <tr>
            <th>Id</th>
            <th>姓?名?</th>
            <th>邮ê箱?</th>
            <th>个?人?主÷页3</th>
            <th>生ú日?</th>
            <th>&nbsp;</th>
            </tr>
        </thead>
        <tbody>
        <%foreach (var item in ViewData.Model)
            {%>
            <tr>
                <td><%=item.Id%></td>
                <td><%=item.Name%></td>
                <td><%=item.EMail%></td>
                <td><%=item.Url%></td>
                <td><%=item.Birthday.ToShortDateString()%></td>
                <td><%=Html.ActionLink("编辑", "Edit", new {id = item.Id},
new {@class = "d", width = 600})%></td>
            </tr>
        <%}%>
        </tbody>
    </table>

样式啥的控制和上一篇差不多我不在这里说了

DEMO中的效果图:

image

image

 image

image

DEMO下载:/Files/francis67/MvcDemo.rar