一个支持普通分页和综合分页的MVC分页Helper(2)

using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace System.Web.Mvc { public class PagerQuery<TPager,TEntityList> { public PagerQuery(TPager pager, TEntityList entityList) { this.Pager = pager; this.EntityList = entityList; } public TPager Pager { get; set; } public TEntityList EntityList { get; set; } } }

PageInfo.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace System.Web.Mvc { public class PagerInfo { public int RecordCount { get; set; } public int CurrentPageIndex { get; set; } public int PageSize { get; set; } } }

使用示例:

@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PagerQuery<PagerInfo, IList<NewsArticleInfo>>>" %> <asp:Content ContentPlaceHolderID="TitleContent" runat="server"> NewsList </asp:Content> <asp:Content ContentPlaceHolderID="MainContent" runat="server"> <h2>NewsList</h2> <table> <tr> <th></th> <th> NoteID </th> <th> Title </th> <th> Author </th> <th> Hit </th> <th> ReplyNum </th> </tr> <% foreach (var item in Model.EntityList) { %> <tr> <td> <%= Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) %> | <%= Html.ActionLink("Details", "NewsDetail", new { noteID=item.NoteID })%> </td> <td> <%= Html.Encode(item.NoteID) %> </td> <td> <%= Html.Encode(item.Title) %> </td> <td> <%= Html.Encode(item.Author)%> </td> <td> <%= Html.Encode(item.Hit)%> </td> <td> <%= Html.Encode(item.ReplyNum)%> </td> </tr> <% } %> </table> <p> <%=Html.Pager("pager",Model.Pager.CurrentPageIndex,Model.Pager.PageSize,Model.Pager.RecordCount,PageMode.Numeric) %> </p> </asp:Content>

controler:

[AcceptVerbs(HttpVerbs.Get)] public ActionResult NewsList(int boardID,int? page) { PagerInfo pager = new PagerInfo(); NewsArticleInfo info = new NewsArticleInfo(); info.NewsBoard = new NewsBoardInfo(); info.NewsBoard.BoardID = boardID; pager.RecordCount = Resolve<INewsBLL>().GetArticleDataList(info, ArticleTypeEnum.Pass); pager.PageSize = 10; pager.CurrentPageIndex = (page!=null?(int)page:1); IList<NewsArticleInfo> result = Resolve<INewsBLL>().GetArticleDataList(pager.CurrentPageIndex, pager.PageSize, ArticleTypeEnum.Pass, info); PagerQuery<PagerInfo, IList<NewsArticleInfo>> query = new PagerQuery<PagerInfo, IList<NewsArticleInfo>>(pager,result); return View(query); }

源码下载:(jb51.net).rar

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjydyy.html