Example #1
0
        public static MvcHtmlString Page <T>(this HtmlHelper htmlHelper, string actionName, object routeValues, PageResult <T> pageViewData)
        {
            System.Text.StringBuilder pageBuilder = new Text.StringBuilder();
            pageBuilder.Append("<ul class=\"pagination pagination-split\"><li class=\"disabled\"><a href=\"#\">" + pageViewData.Total + "条</a></li>");

            if (pageViewData.HasPreviousPage)
            {
                pageBuilder.Append("<li>");
                RouteValueDictionary newrouteValues = new RouteValueDictionary(routeValues);
                newrouteValues.Add("page", pageViewData.PreviousPage);
                pageBuilder.Append(System.Web.Mvc.Html.LinkExtensions.ActionLink(htmlHelper, "<<", actionName, newrouteValues, null).ToHtmlString());
                pageBuilder.Append("</li>");
            }

            if (pageViewData.CurrentPage <= 5)
            {
                for (int i = 1; i < 11 && i < pageViewData.TotalPages + 1; i++)
                {
                    if (i != pageViewData.CurrentPage)
                    {
                        pageBuilder.Append("<li>");
                        RouteValueDictionary newrouteValues = new RouteValueDictionary(routeValues);
                        newrouteValues.Add("page", i);
                        pageBuilder.Append(System.Web.Mvc.Html.LinkExtensions.ActionLink(htmlHelper, i.ToString(), actionName, newrouteValues, null).ToHtmlString());
                    }
                    else
                    {
                        pageBuilder.Append("<li class='active'>");
                        pageBuilder.Append("<a href='javascript:viod(0)'>" + i.ToString() + " </a>");
                    }
                    pageBuilder.Append("</li>");
                }
            }
            else
            {
                for (int i = pageViewData.CurrentPage - 5; i < pageViewData.CurrentPage + 5 && i < pageViewData.TotalPages + 1; i++)
                {
                    if (i != pageViewData.CurrentPage)
                    {
                        pageBuilder.Append("<li>");
                        RouteValueDictionary newrouteValues = new RouteValueDictionary(routeValues);
                        newrouteValues.Add("page", i);
                        pageBuilder.Append(System.Web.Mvc.Html.LinkExtensions.ActionLink(htmlHelper, i.ToString(), actionName, newrouteValues, null).ToHtmlString());
                    }
                    else
                    {
                        pageBuilder.Append("<li class='active'>");
                        pageBuilder.Append("<a href='javascript:viod(0)'>" + i.ToString() + " </a>");
                    }
                    pageBuilder.Append("</li>");
                }
            }

            if (pageViewData.HasNextPage)
            {
                pageBuilder.Append("<li>");
                RouteValueDictionary newrouteValues = new RouteValueDictionary(routeValues);
                newrouteValues.Add("page", pageViewData.NextPage);
                pageBuilder.Append(System.Web.Mvc.Html.LinkExtensions.ActionLink(htmlHelper, ">>", actionName, newrouteValues, null).ToHtmlString());
                pageBuilder.Append("</li>");
            }
            pageBuilder.Append("</ul>");
            return(MvcHtmlString.Create(pageBuilder.ToString()));
        }
Example #2
0
        /// <summary>
        /// 从<see cref="T:System.Collections.Generic.IEnumerable`1" />创建一个<see cref="T:System.IPageResult`1" />
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <param name="source"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public static IPageResult <TSource> ToPage <TSource>(this IEnumerable <TSource> source, int pageIndex, int pageSize)
        {
            int total = source.Select(o => 1).Count();

            return(PageResult.Create(source.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(), pageIndex, pageSize, total));
        }