基于ASP.NET的MVC框架下的MvcPaper分页控件的使用技术
2024-08-26 18:59:20
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Webdiyer.WebControls.Mvc; namespace MvcGuestBook.Common
{
public static class MvcPaper
{
/// <summary>
/// 重写PagedList可以使用List集合数据
/// </summary>
/// <typeparam name="T">实体类</typeparam>
/// <param name="allItems">IList集合</param>
/// <param name="pageIndex">页码</param>
/// <param name="pageSize">一页显示的数量</param>
/// <returns>PagedList<T></returns>
public static PagedList<T> ToPagedList<T>(this IList<T> allItems, int pageIndex, int pageSize)
{
if (pageIndex < )
pageIndex = ;
var itemIndex = (pageIndex - ) * pageSize;
var pageOfItems = allItems.Skip(itemIndex).Take(pageSize);
var totalItemCount = allItems.Count();
return new PagedList<T>(pageOfItems, pageIndex, pageSize, totalItemCount);
}
}
} public ActionResult IndexPage(int? id = )
{
IList<Message> userList = new List<Message>();
int totalCount = ;
int pageIndex = id ?? ;
userList = Common.Common.TableToList<Message>(_messageRepository.GetLists("").Tables[]); //var queryable = userList.AsQueryable(); //userList = SC.Repository.User.GetList("", 2, (pageIndex - 1) * 2, out totalCount); PagedList<Message> mPage = Common.MvcPaper.ToPagedList<Message>(userList, pageIndex, );
totalCount = userList.Count;
mPage.TotalItemCount = totalCount;
mPage.CurrentPageIndex = (int)(id ?? );
return View(mPage);
} <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PagedList<MvcGuestBook.Models.Message>>" %> <%@ Import Namespace="Webdiyer.WebControls.Mvc"%> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
IndexPage
</asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>IndexPage</h2> <table>
<tr>
<th></th>
<th>
ID
</th>
<th>
MemberID
</th>
<th>
Body
</th>
<th>
IsSecret
</th>
<th>
AdminReply
</th>
<th>
AdminReplyTime
</th>
<th>
CreateTime
</th>
</tr> <% foreach (var item in Model) { %> <tr>
<td>
<%: Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) %> |
<%: Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ })%> |
<%: Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })%>
</td>
<td>
<%: item.ID %>
</td>
<td>
<%: item.MemberID %>
</td>
<td>
<%: item.Body %>
</td>
<td>
<%: item.IsSecret %>
</td>
<td>
<%: item.AdminReply %>
</td>
<td>
<%: String.Format("{0:g}", item.AdminReplyTime) %>
</td>
<td>
<%: String.Format("{0:g}", item.CreateTime) %>
</td>
</tr> <% } %> </table> <%: Html.Pager(Model, new PagerOptions
{ PageIndexParameterName="ID",ShowPageIndexBox=true,
FirstPageText="首页",PrevPageText="上一页",NextPageText="下一页",LastPageText="末页",PageIndexBoxType=PageIndexBoxType.TextBox,
PageIndexBoxWrapperFormatString="请输入页数{0}",GoButtonText="转到"})%> <br />
>>分页 共有 <%: Model.TotalItemCount %> 篇留言 <%: Model.CurrentPageIndex %>/<%: Model.TotalPageCount %>
<p>
<%: Html.ActionLink("Create New", "Create") %>
</p> <p>
<%: Html.ActionLink("返回第一种分页方法", "Index") %>
</p> </asp:Content> 详细源码示例链接: http://download.csdn.net/download/u012949335/10189580
最新文章
- 使用Windows EFS(怎么给文件夹加密)进行文件加密
- LaTex随笔
- C#语句1:选择语句二(switch break)
- 【转】What&#39;s the difference between simulation and emulation
- C#实现汉字转换为拼音缩写的代码
- CentOS下Apache+SVN+LDAP的安装与配置
- VC中遍历目标进程中的模块
- (转)swfobject.js 详细解说
- java接口的理解
- [转]Flash、Flex、AS3.0框架及类库资源收集之十全大补
- 使用Nodejs进行反向代理
- [HNOI2013]游走 期望+高斯消元
- odoo权限机制
- 利用scrollintoview方法模拟聊天室收到新消息
- JavaWeb三大组件之Filter
- winform使用相关
- ubuntun与qt下载地址
- LeetCode(2): 两数相加
- 在win10中解决 你要以何方式打开此 .xlsx
- #ifndef HeaderName_h #define HeaderName_h #endif 使用详解
热门文章
- Spring cloud Hystrix使用@HystrixCommand使用Hystrix组件及@EnableCircuitBreaker原理介绍
- leetcode225
- 「小程序JAVA实战」小程序的微信api菜单操作(67)
- oracle ROW_NUMBER用法
- struts2配置默认首页
- S导入部门数据 更新父部门、责任人
- C++实现:把一个文件夹里的冗余文件(.txt)删除
- 23.Merge k Sorted Lists (Array, Queue; Sort)
- oralce 知识
- KVC(forKey,forKeyPath)