当前位置: 首页>>代码示例>>C#>>正文


C# UrlHelper.StateUrl方法代码示例

本文整理汇总了C#中System.Web.Mvc.UrlHelper.StateUrl方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.StateUrl方法的具体用法?C# UrlHelper.StateUrl怎么用?C# UrlHelper.StateUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.UrlHelper的用法示例。


在下文中一共展示了UrlHelper.StateUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Pager

        public static MvcHtmlString Pager(this HtmlHelper htmlHelper, IPagedEnumerable list, int maximumNumericLinks, string pagerPreviousClass, string pagerNextClass, string pagerDisabledClass, string pagingNumberClass, string pagingNumberCurrentClass)
        {
            if (maximumNumericLinks % 2 != 1)
                throw new ArgumentException("Value must be an odd number.", "maximumNumericLinks");

            var url = new UrlHelper(htmlHelper.ViewContext.RequestContext);

            #region Previous Link

            var prev = new TagBuilder("div");
            prev.AddCssClass("pagerPreviousHolder");

            var prevLink = new TagBuilder("a");
            prevLink.SetInnerText("<< Prev");
            if (list.Page > 1)
                prevLink.MergeAttribute("href", url.StateUrl(new { page = list.Page - 1 }));
            else
                prevLink.AddCssClass(pagerDisabledClass);
            prevLink.AddCssClass(pagerPreviousClass);

            prev.InnerHtml = prevLink.ToString(TagRenderMode.Normal);

            #endregion
            #region Numeric Links

            var numerics = new TagBuilder("div");
            numerics.AddCssClass("pagerNumberHolder");

            if (list.TotalPages > 0)
            {

                int pagingStartNumber = -1;
                int pagingEndNumber = -1;

                if ((list.TotalPages >= maximumNumericLinks) && (list.Page > (int)Math.Ceiling((double)maximumNumericLinks / 2D)))
                    pagingStartNumber = list.Page - (int)Math.Floor((double)maximumNumericLinks / 2D);
                else
                    pagingStartNumber = 1;

                if (list.TotalPages >= (pagingStartNumber + maximumNumericLinks))
                    pagingEndNumber = pagingStartNumber + (maximumNumericLinks - 1);
                else
                {
                    if (list.TotalPages >= maximumNumericLinks)
                        pagingStartNumber = list.TotalPages - (maximumNumericLinks - 1);

                    pagingEndNumber = list.TotalPages;
                }

                //for (int i = pagingStartNumber; i <= pagingEndNumber; i++)
                for (int i = pagingEndNumber; i >= pagingStartNumber; i--)
                {
                    var numberTag = new TagBuilder("a");
                    numberTag.SetInnerText(i.ToString());
                    if (i == list.Page) 
                        numberTag.AddCssClass(pagingNumberCurrentClass);
                    else
                        numberTag.MergeAttribute("href", url.StateUrl(new { page = i }));
                    numberTag.AddCssClass(pagingNumberClass);                    
                    numerics.InnerHtml = numerics.InnerHtml + numberTag.ToString();
                }

            }
            else
            {
                //numerics.InnerHtml = "&nbsp;"; // Stops div colapsing
            }

            #endregion
            #region Next Link

            var next = new TagBuilder("div");
            next.AddCssClass("pagerNextHolder");

            var nextLink = new TagBuilder("a");
            nextLink.SetInnerText("Next >>");
            if (list.Page < list.TotalPages)
                nextLink.MergeAttribute("href", url.StateUrl(new { page = list.Page + 1 }));
            else
                nextLink.AddCssClass(pagerDisabledClass);
            nextLink.AddCssClass(pagerNextClass);

            next.InnerHtml = nextLink.ToString();

            #endregion
            
            return MvcHtmlString.Create(string.Format("<div class=\"pagerHolder\">{0}{3}{0}{2}{0}{1}</div>", Environment.NewLine, prev, numerics, next));
        }
开发者ID:wduffy,项目名称:Toltech.Mvc,代码行数:88,代码来源:Pager.cs


注:本文中的System.Web.Mvc.UrlHelper.StateUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。