日期:2014-05-17 浏览次数:20561 次
public IList<web_AppLogo> list()
{
try
{
var data = db.web_AppLogo.ToList();
return data;
}
catch (Exception)
{
return null;
}
}
public interface IAppLogoService
{
IList<web_AppLogo> list();
}
public ActionResult List(int? id, int? Page)
{
var data = service.list();
int PageSize = 10;
int PageIndex = Page ?? 1;
if (PageIndex < 1) PageIndex = 1;
ViewData["PageIndex"] = PageIndex;
ViewData["PageSize"] = PageSize;
ViewData["ReCordCount"] = data.Count();
return View(WebPage.GetPageList(data, PageIndex, PageSize));
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Text;
namespace System.Web.Mvc
{
public static class WebPage
{
public static IQueryable<T> GetPageList<T>(IOrderedQueryable<T> List, int PageIndex, int PageSize)
{
int PageCount = GetPageCount(PageSize, List.Count());
PageIndex = CheckPageIndex(PageIndex, PageCount);
return List.Skip((PageIndex - 1) * PageSize).Take(PageSize);
}
public static int GetPageCount(int PageSize, int recordCount)
{
int PageCount = recordCount % PageSize == 0 ? recordCount / PageSize : recordCount / PageSize + 1;
if (PageCount < 1) PageCount = 1;
return PageCount;
}
public static int CheckPageIndex(int PageIndex, int PageCount)
{
if (PageIndex > PageCount) PageIndex = PageCount;
if (PageIndex < 1) PageIndex = 1;
return PageIndex;
}
public enum WebPageMode { Normal, Numeric, GroupNumeric }
public static MvcHtmlString ShowWebPage(this HtmlHelper Html, string urlFormat, int PageIndex, int PageSize, int recordCount, WebPageMode Mode)
{
urlFormat = urlFormat.Replace("%7B0%7D", "{0}");
int PageCount = GetPageCount(PageSize, recordCount);
StringBuilder TempHtml = new StringBuilder();
TempHtml.AppendFormat("总共{0}条记录,共{1}页,当前第{2}页 ", recordCount, PageCount, PageIndex);
if (PageIndex == 1)
{
TempHtml.Append("首页 上一页 ");
}
else
{
TempHtml.AppendFormat("<a href=\"{0}\">首页</a> ", string.Format(urlFormat, 1))
.AppendFormat("<a href=\"{0}\">上一页</a> ", string.Format(urlFormat, PageIndex - 1));
}
// 数字分页
switch (Mode)
{
case WebPageMode.Numeric: