public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, string protocol = null, string hostName = null, string fragment = null, object routeValues = null, string accessKey = null, string charset = null, string coords = null, string cssClass = null, string dir = null, string hrefLang = null, string id = null, string lang = null, string name = null, string rel = null, string rev = null, string shape = null, string style = null, string target = null, string title = null) { return(LinkExtensions.RouteLink( htmlHelper, linkText, routeName, protocol, hostName, fragment, routeValues as RouteValueDictionary ?? new RouteValueDictionary(routeValues), AnchorAttributes(accessKey, charset, coords, cssClass, dir, hrefLang, id, lang, name, rel, rev, shape, style, target, title) )); }
public MvcHtmlString InitPagerHtml(HtmlHelper htmlHelper) { MvcHtmlString result; if (this.TotalRecords == 0) { result = MvcHtmlString.Empty; } else { int num = this.TotalRecords / this.PageSize; if (this.TotalRecords % this.PageSize > 0) { num++; } string text = "<a href='#'>1</a>"; string value = "<span>{totalText}:</span> <span>{totalRecords}</span> <span>{totalRecordsText}</span> <span>{first}</span> <span> {previous}</span> <span> {numberRange}</span> <span>{next}</span> <span>{last}</span> <span>{pageCount} pages</span>"; if (string.IsNullOrEmpty(this.ControllerName) || string.IsNullOrEmpty(this.ActionName)) { throw new Exception("controllerName and actionName must be specified for PageLinks."); } RouteValueDictionary routeValueDictionary = new RouteValueDictionary(this.RouteValues); routeValueDictionary.Add("controller", this.ControllerName); routeValueDictionary.Add("action", this.ActionName); routeValueDictionary.Add("page", 1); string newValue = LinkExtensions.RouteLink(htmlHelper, this.FirstText, routeValueDictionary).ToString(); routeValueDictionary["page"] = num; string newValue2 = LinkExtensions.RouteLink(htmlHelper, this.LastText, routeValueDictionary).ToString(); routeValueDictionary["page"] = this.PageIndex + 1; string newValue3 = LinkExtensions.RouteLink(htmlHelper, this.NextText, routeValueDictionary).ToString(); routeValueDictionary["page"] = this.PageIndex - 1; string newValue4 = LinkExtensions.RouteLink(htmlHelper, this.PreviousText, routeValueDictionary).ToString(); if (this.PageIndex == 1) { newValue = this.FirstText; newValue4 = this.PreviousText; } if (this.PageIndex == num) { newValue3 = this.NextText; newValue2 = this.LastText; } if (num <= this.PageRange) { text = ""; for (int i = 1; i <= num; i++) { if (this.PageIndex == i) { text += i.ToString(); } else { routeValueDictionary["page"] = i; text += LinkExtensions.RouteLink(htmlHelper, i.ToString(), routeValueDictionary).ToString(); } text += " "; } } else { for (int i = 0; i <= num / this.PageRange; i++) { int num2 = this.PageRange * i; int num3 = this.PageRange * (i + 1); if (this.PageIndex > num2 && this.PageIndex <= num3) { text = ""; for (int j = num2 + 1; j <= num3; j++) { if (this.PageIndex == j) { text += j.ToString(); } else { routeValueDictionary["page"] = j; text += LinkExtensions.RouteLink(htmlHelper, j.ToString(), routeValueDictionary).ToString(); } text += " "; } } } } StringBuilder stringBuilder = new StringBuilder(value); stringBuilder.Replace("{totalText}", this.TotalText).Replace("{totalRecords}", this.TotalRecords.ToString()).Replace("{totalRecordsText}", this.TotalRecordsText).Replace("{first}", newValue).Replace("{totalRecordsText}", this.TotalRecordsText); stringBuilder.Replace("{previous}", newValue4).Replace("{numberRange}", text).Replace("{next}", newValue3).Replace("{last}", newValue2).Replace("{pageCount}", num.ToString()); result = MvcHtmlString.Create(stringBuilder.ToString()); } return(result); }