遇到这个错误:无法从用法中推导出方法
无法从用法中推导出方法“System.Web.Mvc.WebPage.GetPageList<T>(System.Linq.IOrderedQueryable<T>, int, int)”的类型实参。请尝试显式指定类型实参。
D:\项目练习\MvcTest\MvcApplication\MvcApplication\Areas\AdminManage\Controllers\AppLogoController.cs
下面是我的代码,我都贴出来了
Service
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: TempHtml.Append(GetNumericPage(urlFormat, PageIndex, PageSize, PageCount)); break; case WebPageMode.GroupNumeric: TempHtml.Append(GetGroupNumericPage(urlFormat, PageIndex, PageSize, PageCount)); break; } if (PageIndex == PageCount) { TempHtml.Append("下一页 末页"); } else { TempHtml.AppendFormat("<a href=\"{0}\">下一页</a> ", string.Format(urlFormat, PageIndex + 1)) .AppendFormat("<a href=\"{0}\">末页</a>", string.Format(urlFormat, PageCount)); } return MvcHtmlString.Create(TempHtml.ToString()); } /// <summary> /// 分组数字分页 /// </summary> /// <param name="urlFormat"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="pageCount"></param> /// <returns></returns> public static string GetGroupNumericPage(string urlFormat, int pageIndex, int pageSize, int pageCount) { int GroupChildCount = 10; // 分组显示个数 int DGroup = pageIndex / GroupChildCount; //当前组 int GroupCount = pageCount / GroupChildCount; //组数 //如果正好是当前组最后一页 不进入下一组 if (pageIndex % GroupChildCount == 0) DGroup--; //当前组数量 int GroupSpan = (DGroup == GroupCount) ? pageCount % GroupChildCount : GroupChildCount; StringBuilder TempHtml = new StringBuilder(); for (int i = DGroup * GroupChildCount + 1; i <= DGroup * GroupChildCount + GroupSpan; i++) { if (i == pageIndex) TempHtml.AppendFormat("<span style=\"color:red\">{0}</span> ", i); else TempHtml.AppendFormat("<a href=\"{0}\">{1}</a> ", string.Format(urlFormat, i), i); } return TempHtml.ToString(); } /// <summary> /// 数字分页 /// </summary> /// <param name="urlFormat"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="pageCount"></param> /// <returns></returns> public static string GetNumericPage(string urlFormat, int pageIndex, int pageSize, int pageCount) { int SpanNum = 9; int BeginNum = pageIndex - (SpanNum - 1) / 2; if (BeginNum < 1) BeginNum = 1; int EndNum = pageIndex + (SpanNum - 1) / 2; if (EndNum > pageCount) EndNum = pageCount; StringBuilder TempHtml = new StringBuilder(); for (int i = BeginNum; i <= EndNum; i++) { if (i == pageIndex) TempHtml.AppendFormat("<span style=\"color:red\">{0}</span> ", i); else TempHtml.AppendFormat("<a href=\"{0}\">{1}</a> ", string.Format(urlFormat, i), i); } return TempHtml.ToString(); } }}