ChiakiYu.Common.Extensions.Html.HtmlHelperPaginationExtensions.GetPagingNavigateUrl C# (CSharp) 메소드

GetPagingNavigateUrl() 공개 정적인 메소드

构建分页按钮的链接
public static GetPagingNavigateUrl ( this htmlHelper, int pageIndex, string currentUrl = null ) : string
htmlHelper this 被扩展的HtmlHelper
pageIndex int 当前页码
currentUrl string
리턴 string
        public static string GetPagingNavigateUrl(this HtmlHelper htmlHelper, int pageIndex, string currentUrl = null)
        {
            object pageIndexObj;
            if (htmlHelper.ViewContext.RouteData.Values.TryGetValue("pageIndex", out pageIndexObj))
            {
                htmlHelper.ViewContext.RouteData.Values["pageIndex"] = pageIndex;

                return UrlHelper.GenerateUrl(null, null, null, htmlHelper.ViewContext.RouteData.Values,
                    RouteTable.Routes, htmlHelper.ViewContext.RequestContext, true);
            }

            if (string.IsNullOrEmpty(currentUrl))
                currentUrl = HttpUtility.HtmlEncode(htmlHelper.ViewContext.HttpContext.Request.RawUrl);

            if (currentUrl.IndexOf("?", StringComparison.InvariantCultureIgnoreCase) == -1)
            {
                return currentUrl + string.Format("?pageIndex={0}", pageIndex);
            }
            if (currentUrl.IndexOf("pageIndex=", StringComparison.InvariantCultureIgnoreCase) == -1)
                return currentUrl + string.Format("&pageIndex={0}", pageIndex);
            return Regex.Replace(currentUrl, @"pageIndex=(\d+\.?\d*|\.\d+)", "pageIndex=" + pageIndex,
                RegexOptions.IgnoreCase | RegexOptions.Compiled);
        }