ASP.NET MVC分页 demo
- //servcie
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using StaticMvc.Models;
- using Webdiyer.WebControls.Mvc;
- namespace StaticMvc
- {
- public class ArticleService
- {
- public PagedList<Article> GetPagedList(int page, int count)
- {
- PagedList<Article> result = GetList().ToPagedList(page, count);
- result.TotalItemCount = GetList().Count();
- result.CurrentPageIndex = page;
- return result;
- }
- public IQueryable<Article> GetList()
- {
- List<Article> list = new List<Article>();
- for (int i = 1; i < 100; i++)
- {
- list.Add(new Article() { Id = i, Title = "测试标题" + i, UpdateTime = DateTime.Now });
- }
- return list.AsQueryable<Article>();
- }
- }
- }
- //controller
- //[StaticFileFilter]
- public ActionResult Index(int page = 1)
- {
- int count = 5;
- PagedList<Article> list = articleService.GetPagedList(page, count);
- ViewBag.ArticleList = list;
- return View();
- }
- //html
- @using Webdiyer.WebControls.Mvc;
- @{
- ViewBag.Title = "Index";
- }
- <h2>Index</h2>
- <p>this is index content</p>
- <h1>ViewBag.ArticleList</h1>
- <ul>
- @foreach (StaticMvc.Models.Article item in ViewBag.ArticleList)
- {
- <li>@(item.Title + "(" + item.UpdateTime + ")")</li>
- }
- </ul><br />
- <style>
- .pager {
- margin: 10px;
- }
- .pager select, .pager a {
- border: 1px solid #eee;
- color: #555;
- text-decoration: none;
- padding:5px;
- font-size:14px;
- }
- .pager a:hover, .pager a.current {
- border: 1px solid #2aa0f5;
- background: #2aa0f5;
- color:#fff;
- }
- </style>
- @Html.Pager(ViewBag.ArticleList as PagedList<StaticMvc.Models.Article>, new PagerOptions
- {
- ShowDisabledPagerItems = false,
- PageIndexParameterName = "page",
- ShowPageIndexBox = true,
- FirstPageText = "首页",
- PrevPageText = "上一页",
- NextPageText = "下一页",
- LastPageText = "末页",
- ShowGoButton = false,
- CssClass = "pager",
- NumericPagerItemCount = 5,
- CurrentPagerItemWrapperFormatString = "<a class='current'>{0}</a>",
- PageIndexBoxType = PageIndexBoxType.DropDownList
- })
- <br />
- @Html.Partial("_SideBar");
附件:
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · 使用jenkins远程布署.net项目
- · c#/ASP.NET向百度站长平台主动推送URL
- · ASP.NET分页组装HTML代码
- · linux asp.net用httpWebRequest或WebClient访问https站点
- · 让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求
- · 支持高并发的IIS Web服务器常用设置
- · LINUX下部署ASP.NET:无需安装Mono的Jexus“独立版”
- · 最新asp.net/c#使用Memcached完整示例及注意事项
- · 讨论:关于ASP.NET用Timer定时执行问题
- · ASP.NET获取工程根目录
- · Asp.Net里的Cookies用法
- · ASP.NET实现插件功能