基于ASP.NET的MVC框架下的MvcPaper分页控件的使用技术

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Webdiyer.WebControls.Mvc;

namespace MvcGuestBook.Common
{
    public static class MvcPaper
    {
        public static PagedList<T> ToPagedList<T>(this IList<T> allItems, int pageIndex, int pageSize)
        {
            if (pageIndex < 1)
                pageIndex = 1;
            var itemIndex = (pageIndex - 1) * 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 = 1)
        {
            IList<Message> userList = new List<Message>();
            int totalCount = 0;
            int pageIndex = id ?? 1;
            userList = Common.Common.TableToList<Message>(_messageRepository.GetLists("").Tables[0]);

            //var queryable = userList.AsQueryable();

            //userList = SC.Repository.User.GetList("", 2, (pageIndex - 1) * 2, out totalCount);

            PagedList<Message> mPage = Common.MvcPaper.ToPagedList<Message>(userList, pageIndex, 15);
            totalCount = userList.Count;
            mPage.TotalItemCount = totalCount;
            mPage.CurrentPageIndex = (int)(id ?? 1);
            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/10200810


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值