private static string ReleaseLink(HtmlHelper html, string linkText, string releaseName, string action, string currentAction)
 {
     if (!string.Equals(action, currentAction, StringComparison.InvariantCultureIgnoreCase))
     {
         var id = (action == "Delete") ? "delete" + releaseName : "goTo" + releaseName + action;
         return html.RouteLink(linkText, "Release", new { releaseName, action }, new { id = id }).ToString();
     }
     return MvcHtmlString.Create(linkText).ToString();
 }
Example #2
0
 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, string protocol, string hostName, string fragment, Hash routeValues, Hash htmlAttributes)
 {
     return(htmlHelper.RouteLink(linkText, routeName, protocol, hostName, fragment, HashHelper.ToRouteValueDictionary(routeValues), HashHelper.ToRouteValueDictionary(htmlAttributes)));
 }
Example #3
0
        public static string CreatorRouteLink(HtmlView view, ViewContext context, Match linkMatch)
        {
            var linkAttributes = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);

            MatchCollection linkAttributeMatches = RegularExpressions.AttributeNameValue.Matches(linkMatch.Value);

            foreach (Match linkAttributeMatch in linkAttributeMatches)
            {
                string attributeName = linkAttributeMatch.Groups[1].Value.Trim();

                if (String.Equals("routeValues", attributeName, StringComparison.OrdinalIgnoreCase) ||
                    String.Equals("htmlAttributes", attributeName, StringComparison.OrdinalIgnoreCase))
                {
                    linkAttributes[attributeName] = DeserializeObjectAsDictionary(linkAttributeMatch.Groups[2].Value);
                }
                else
                {
                    linkAttributes[attributeName] = linkAttributeMatch.Groups[2].Value.Trim();
                }
            }

            object route, routeValues, htmlAttributes;

            linkAttributes.TryGetValue("route", out route);

            if (linkAttributes.TryGetValue("routeValues", out routeValues) && routeValues is IDictionary<string, object>)
            {
                routeValues = new RouteValueDictionary((IDictionary<string, object>) routeValues);
            }
            else
            {
                routeValues = null;
            }

            if (!linkAttributes.TryGetValue("htmlAttributes", out htmlAttributes) || !(htmlAttributes is IDictionary<string, object>))
            {
                htmlAttributes = null;
            }

            string value = linkMatch.Groups[2].Value;

            if (IsNullOrEmpty(value))
            {
                value = "route link";
            }

            var helper = new HtmlHelper(context, view);
            string link = helper.RouteLink(ValueToken,
                                           route as string,
                                           (RouteValueDictionary) routeValues,
                                           (IDictionary<string, object>) htmlAttributes).ToHtmlString();

            return link.Replace(ValueToken, value);
        }
        private static void BuildChildMenu(HtmlHelper html, NamedRoute route, TagBuilder li)
        {
            // convert menu entry to dropdown
            li.AddCssClass("dropdown");
            li.InnerHtml = "<a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">" + route.DisplayName +
                           "<b class=\"caret\"></b></a>";

            // build LIs for the children
            var ul = new TagBuilder("ul");
            ul.AddCssClass("dropdown-menu");
            foreach (var child in route.Children)
            {
                var childLi = new TagBuilder("li");
                childLi.InnerHtml = html.RouteLink(child.DisplayName, child.Name).ToString();
                ul.InnerHtml += childLi.ToString();

                // support for drop down list breaks 
                if (child.ShouldBreakAfter)
                {
                    var breakLi = new TagBuilder("li");
                    breakLi.AddCssClass("divider");
                    ul.InnerHtml += breakLi.ToString();
                }
            }

            // append the UL
            li.InnerHtml = "<a href='#' class='dropdown-toggle' data-toggle='dropdown'>" + route.DisplayName +
                           " <b class='caret'></b></a>" + ul.ToString();
        }
Example #5
0
 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, ActionResult result, IDictionary <string, object> htmlAttributes, string protocol, string hostName, string fragment)
 {
     return(htmlHelper.RouteLink(linkText, routeName, protocol ?? result.GetT4MVCResult().Protocol, hostName, fragment, result.GetRouteValueDictionary(), htmlAttributes));
 }
Example #6
0
 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, ActionResult result, IDictionary <string, object> htmlAttributes)
 {
     return(htmlHelper.RouteLink(linkText, null, result, htmlAttributes, null, null, null));
 }
Example #7
0
        private string Pager(string routeName, string actionName, string controllerName, IDictionary <string, object> values, string pageParamName, int pageCount, int noOfPageToShow, int noOfPageInEdge, int currentPage)
        {
            Func <string, int, string> getPageLink = (text, page) =>
            {
                RouteValueDictionary newValues = new RouteValueDictionary();

                foreach (KeyValuePair <string, object> pair in values)
                {
                    if (!pair.Key.Equals("controller", StringComparison.OrdinalIgnoreCase) &&
                        !pair.Key.Equals("action", StringComparison.OrdinalIgnoreCase))
                    {
                        newValues[pair.Key] = pair.Value;
                    }
                }

                if (page > 0)
                {
                    newValues[pageParamName] = page;
                }

                string link;

                if (!string.IsNullOrWhiteSpace(routeName))
                {
                    link = htmlHelper.RouteLink(text, routeName, newValues).ToHtmlString();
                }
                else
                {
                    actionName     = actionName ?? values["action"].ToString();
                    controllerName = controllerName ?? values["controller"].ToString();

                    link = htmlHelper.ActionLink(text, actionName, controllerName, newValues, null).ToHtmlString();
                }

                return(string.Concat(" ", link));
            };

            StringBuilder pagerHtml = new StringBuilder();

            if (pageCount > 1)
            {
                pagerHtml.Append("<div class=\"pager\">");

                double half = Math.Ceiling(Convert.ToDouble(Convert.ToDouble(noOfPageToShow) / 2));

                int start = Convert.ToInt32((currentPage > half) ? Math.Max(Math.Min((currentPage - half), (pageCount - noOfPageToShow)), 0) : 0);
                int end   = Convert.ToInt32((currentPage > half) ? Math.Min(currentPage + half, pageCount) : Math.Min(noOfPageToShow, pageCount));

                pagerHtml.Append(currentPage > 1 ? getPageLink("Previous", currentPage - 1) : " <span class=\"disabled\">Previous</span>");

                if (start > 0)
                {
                    int startingEnd = Math.Min(noOfPageInEdge, start);

                    for (int i = 0; i < startingEnd; i++)
                    {
                        int pageNo = i + 1;

                        pagerHtml.Append(getPageLink(pageNo.ToString(Culture.Current), pageNo));
                    }

                    if (noOfPageInEdge < start)
                    {
                        pagerHtml.Append(" ...");
                    }
                }

                for (int i = start; i < end; i++)
                {
                    int pageNo = i + 1;

                    pagerHtml.Append(pageNo == currentPage ? " <span class=\"current\">{0}</span>".FormatWith(pageNo) : getPageLink(pageNo.ToString(Culture.Current), pageNo));
                }

                if (end < pageCount)
                {
                    if ((pageCount - noOfPageInEdge) > end)
                    {
                        pagerHtml.Append(" ...");
                    }

                    int endingStart = Math.Max(pageCount - noOfPageInEdge, end);

                    for (int i = endingStart; i < pageCount; i++)
                    {
                        int pageNo = i + 1;
                        pagerHtml.Append(getPageLink(pageNo.ToString(Culture.Current), pageNo));
                    }
                }

                pagerHtml.Append(currentPage < pageCount ? getPageLink("Next", currentPage + 1) : " <span class=\"disabled\">Next</span>");

                pagerHtml.Append("</div>");
            }

            return(pagerHtml.ToString());
        }
        public List <LinkAction> GetCreateActions(HtmlHelper htmlHelper)
        {
            var retVal = new List <LinkAction>();

            if (UserCanCreateEstablishment)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.RouteLink("Create new establishments", "CreateEstablishment"), Description = "Set up a new establishment record."
                });
            }
            if (UserCanBulkCreateAcademies)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Bulk create new academies", "BulkAcademies", "Tools"), Description = "Bulk set up new academy records collectively and not individually."
                });
            }
            if (UserCanBulkCreateFreeSchools)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.RouteLink("Bulk create new free schools", "BulkCreateFreeSchools"), Description = "Bulk set up new free school records collectively and not individually."
                });
            }
            if (UserCanMergeOrAmalgamateEstablishments)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Amalgamate or merge establishments", "MergersTool", "Tools"), Description = "Carry out an amalgamation or merger for establishments."
                });
            }
            if (UserCanCreateChildrensCentreGroup)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Create new children's centre groups or children's centre collaborations", "CreateNewGroup", "Group", new { area = "Groups", type = "ChildrensCentre" }, null), Description = "Set up a new children's centre group or children's centre collaboration record."
                });
            }
            if (UserCanCreateFederationGroup)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Create new federations", "CreateNewGroup", "Group", new { area = "Groups", type = "Federation" }, null), Description = "Set up a new federation record."
                });
            }
            if (UserCanCreateSchoolTrustGroup)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Create new foundation trusts", "CreateNewGroup", "Group", new { area = "Groups", type = "Trust" }, null), Description = "Set up a new foundation trust record."
                });
            }
            if (UserCanCreateAcademySponsor)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Create new academy sponsors", "CreateNewGroup", "Group", new { area = "Groups", type = "Sponsor" }, null), Description = "Set up a new academy sponsor record."
                });
            }
            if (UserCanCreateAcademyTrustGroup)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.ActionLink("Create new academy trusts", "SearchCompaniesHouse", "Group", new { area = "Groups" }, null), Description = "Set up a new academy trust record."
                });
            }
            if (UserCanConvertAcademyTrusts)
            {
                retVal.Add(new LinkAction {
                    Link = htmlHelper.RouteLink("Convert single-academy trusts (SATs)", "GroupConvertSAT2MAT"), Description = "Convert a single-academy trust (SAT) record to a multi-academy trust (MAT) record."
                });
            }

            return(retVal);
        }
Example #9
0
        public MvcHtmlString PagerMenu(HtmlHelper hhelper)
        {
            var content = "";

            content = string.Concat(new object[] { content, "<input type=\"hidden\" value=\"", PageIndex, "\" id=\"page\"/>" });
            if (TotalPages > 1)
            {
                content = content + "<div class=\"pager\">Страницы:&nbsp;";
                if (!DefaultRoutes.ContainsKey("page"))
                {
                    DefaultRoutes.Add("page", 0);
                }
                if (HasPreviousPage)
                {
                    DefaultRoutes["page"] = PageIndex - 1;
                    content = content + (hhelper.RouteLink("<<", MapRuleName, DefaultRoutes,
                                                           (AjaxPager
                                                                ? ((object)
                                                                   new
                    {
                        onclick =
                            "return {0}({1})".FormatWith(PageJSFunction,
                                                         (PageIndex - 1).
                                                         ToString())
                    })
                                                                : ((object)new { })).ToDictionary())) + "&nbsp;";
                }
                string     links       = "";
                string     fmtInactive = "<span>{0}</span>";
                List <int> allowed     = new List <int>();
                if (TotalPages < 15)
                {
                    for (int i = 0; i < 15; i++)
                    {
                        allowed.Add(i);
                    }
                }
                else
                {
                    int start = PageIndex - 8;
                    for (int i = start; i < PageIndex + 8; i++)
                    {
                        allowed.Add(i);
                    }
                    allowed = allowed.Where(x => x >= 0).ToList();
                    int additional = 15 - allowed.Count;
                    if (additional > 0)
                    {
                        int alm  = allowed.Max();
                        int alma = allowed.Max() + additional;
                        for (int i = alm; i < alma; i++)
                        {
                            allowed.Add(i);
                        }
                    }
                    allowed = allowed.Where(x => x <= TotalPages).ToList();
                    if (!allowed.Any())
                    {
                        return(new MvcHtmlString(""));
                    }
                    additional = 15 - allowed.Count;
                    if (additional > 0)
                    {
                        int alm  = allowed.Min();
                        int alma = allowed.Min() - additional;
                        for (int i = alm; i < alma; i--)
                        {
                            allowed.Add(i);
                        }
                    }
                }


                for (int i = 0; i < TotalPages; i++)
                {
                    if (!allowed.Contains(i))
                    {
                        continue;
                    }
                    if ((links.Length > 0) && (i < TotalPages))
                    {
                        links = links + "&nbsp;&nbsp;&nbsp;";
                    }
                    if (i.Equals(PageIndex))
                    {
                        links = links + string.Format(fmtInactive, i + 1);
                    }
                    else
                    {
                        DefaultRoutes["page"] = i;
                        int currentPage = i + 1;

                        if (!AccessHelper.IsMasterPage)
                        {
                            var info = AccessHelper.CurrentPageInfo;
                            if (info != null)
                            {
                                string paramList = string.Join("&",
                                                               DefaultRoutes.Where(
                                                                   x => !x.Key.StartsWith("url")).
                                                               Select(x => string.Format("{0}={1}", x.Key, x.Value))
                                                               .ToList());
                                links += string.Format("<a href=\"/{0}?{1}\">{2}</a>",
                                                       string.Join("/",
                                                                   info.Routes.Where(x => x.Key.Contains("url")).Select(
                                                                       x => x.Value).ToArray()), paramList, currentPage);
                            }
                        }
                        else
                        {
                            links = links + hhelper.RouteLink(currentPage.ToString(),
                                                              MapRuleName,
                                                              DefaultRoutes,
                                                              (AjaxPager
                                                                   ? ((object)
                                                                      new
                            {
                                onclick =
                                    "return {0}({1})".FormatWith(new string[]
                                {
                                    PageJSFunction
                                    , i.ToString()
                                })
                            })
                                                                   : ((object)new { })).ToDictionary());
                        }
                    }
                }
                content = content + links;
                if (HasNextPage)
                {
                    content = content + "&nbsp;";
                    DefaultRoutes["page"] = PageIndex + 1;
                    content = content + hhelper.RouteLink(">>", MapRuleName, DefaultRoutes, (AjaxPager ? ((object)new { onclick = "return {0}({1})".FormatWith(PageJSFunction, (PageIndex + 1).ToString()) }) : ((object)new { })).ToDictionary());
                }
                content = content + "</div>";
            }
            return(new MvcHtmlString(content));
        }
Example #10
0
        public static string Pager(this HtmlHelper helper, string routeName, string actionName, string controllerName, IDictionary <string, object> values, string pageParamName, bool appendQueryString, int pageCount, int noOfPageToShow, int noOfPageInEdge, int currentPage)
        {
            Func <string, int, string> getPageLink = (text, page) =>
            {
                RouteValueDictionary newValues = new RouteValueDictionary();

                foreach (KeyValuePair <string, object> pair in values)
                {
                    Guid t;
                    if ((string.Compare(pair.Key, "controller", StringComparison.OrdinalIgnoreCase) != 0) &&
                        (string.Compare(pair.Key, "action", StringComparison.OrdinalIgnoreCase) != 0) &&
                        Guid.TryParse(pair.Key, out t) == false)
                    {
                        newValues[pair.Key] = pair.Value;
                    }
                }

                if (page > 0)
                {
                    newValues[pageParamName] = page;
                }

                if (appendQueryString)
                {
                    NameValueCollection queryString = helper.ViewContext.HttpContext.Request.QueryString;

                    foreach (string key in queryString)
                    {
                        if (key != null)
                        {
                            if (!newValues.ContainsKey(key))
                            {
                                if (!string.IsNullOrEmpty(queryString[key]))
                                {
                                    newValues[key] = queryString[key];
                                }
                            }
                        }
                    }
                }

                string link;

                if (!string.IsNullOrEmpty(routeName))
                {
                    link = helper.RouteLink(text, routeName, newValues).ToHtmlString();
                }
                else
                {
                    actionName     = actionName ?? values["action"].ToString();
                    controllerName = controllerName ?? values["controller"].ToString();

                    link = helper.ActionLink(text, actionName, controllerName, newValues, null).ToHtmlString();
                }

                return(string.Concat(" ", link));
            };

            var pagerHtml = new StringBuilder();

            if (pageCount > 1)
            {
                pagerHtml.Append("<div class=\"pager\">");

                double half = Math.Ceiling(Convert.ToDouble(Convert.ToDouble(noOfPageToShow) / 2));

                int start = Convert.ToInt32((currentPage > half) ? Math.Max(Math.Min((currentPage - half), (pageCount - noOfPageToShow)), 0) : 0);
                int end   = Convert.ToInt32((currentPage > half) ? Math.Min(currentPage + half, pageCount) : Math.Min(noOfPageToShow, pageCount));

                //if (currentPage > 1)
                //{
                //    pagerHtml.Append(getPageLink("Previous", currentPage - 1));
                //}
                //else
                //{
                //    pagerHtml.Append(" <span class=\"disabled\">Previous</span>");
                //}

                if (start > 0)
                {
                    int startingEnd = Math.Min(noOfPageInEdge, start);

                    for (int i = 0; i < startingEnd; i++)
                    {
                        int pageNo = (i + 1);

                        pagerHtml.Append(getPageLink(pageNo.ToString(Constants.CurrentCulture), pageNo));
                    }

                    if (noOfPageInEdge < start)
                    {
                        pagerHtml.Append("<span>...</span>");
                    }
                }

                for (int i = start; i < end; i++)
                {
                    int pageNo = (i + 1);

                    if (pageNo == currentPage)
                    {
                        pagerHtml.Append(" <span class=\"active\">{0}</span>".FormatWith(pageNo));
                    }
                    else
                    {
                        pagerHtml.Append(getPageLink(pageNo.ToString(Constants.CurrentCulture), pageNo));
                    }
                }

                if (end < pageCount)
                {
                    if ((pageCount - noOfPageInEdge) > end)
                    {
                        pagerHtml.Append("<span>...</span>");
                    }

                    int endingStart = Math.Max(pageCount - noOfPageInEdge, end);

                    for (int i = endingStart; i < pageCount; i++)
                    {
                        int pageNo = (i + 1);
                        pagerHtml.Append(getPageLink(pageNo.ToString(Constants.CurrentCulture), pageNo));
                    }
                }

                //if (currentPage < pageCount)
                //{
                //    pagerHtml.Append(getPageLink("Next", currentPage + 1));
                //}
                //else
                //{
                //    pagerHtml.Append(" <span class=\"disabled\">Next</span>");
                //}

                pagerHtml.Append("</div>");
            }

            return(pagerHtml.ToString());
        }
Example #11
0
 public static MvcHtmlString DocSectionLink(this HtmlHelper helper, string section)
 {
     return(helper.RouteLink(section, "Docs", Url.GetRouteValues(section, null, null),
                             new { @class = "api-section" }));
 }
Example #12
0
 /// <summary>
 /// Lien vers la page de l'utilisateur. Attention l'UserId est shrinké!!
 /// </summary>
 /// <param name="htmlHelper"></param>
 /// <param name="user"></param>
 /// <param name="htmlAttributes"></param>
 /// <returns></returns>
 public static string UserProfileLink(this HtmlHelper htmlHelper, IUserProfile user, object htmlAttributes)
 {
     return(htmlHelper.RouteLink(user.DisplayName, CovCake.Routes.USERINDEX, new { userId = user.UserId.Shrink() }, htmlAttributes));
 }
Example #13
0
 public static string MonCompteUserLink(this HtmlHelper htmlHelper, string linkText, object htmlAttributes)
 {
     return(htmlHelper.RouteLink(linkText, CovCake.Routes.MONCOMPTE, null, htmlAttributes));
 }
Example #14
0
 public static string ProjetIndexLink(this HtmlHelper htmlHelper, string text, IProjet proj, object htmlAttributes)
 {
     return(htmlHelper.RouteLink(text, CovCake.Routes.PROJETINDEX, new { ProjetId = proj.IdProjet }, htmlAttributes));
 }
Example #15
0
 public static MvcHtmlString LogOffLink(this HtmlHelper helper,
                                        string text)
 {
     return(helper.RouteLink(text, "logoff"));
 }
Example #16
0
        private IHtmlString Pager(string routeName, string actionName, string controllerName, IDictionary <string, object> values, string pageParamName, int pageCount, int noOfPageToShow, int noOfPageInEdge, int currentPage)
        {
            Func <string, int, string, string> getPageLink = (text, page, className) =>
            {
                RouteValueDictionary newValues = new RouteValueDictionary();

                foreach (KeyValuePair <string, object> pair in values)
                {
                    if (!pair.Key.Equals("controller", StringComparison.OrdinalIgnoreCase) &&
                        !pair.Key.Equals("action", StringComparison.OrdinalIgnoreCase))
                    {
                        newValues[pair.Key] = pair.Value;
                    }
                }

                if (page > 0)
                {
                    newValues[pageParamName] = page;
                }

                string link;

                if (!string.IsNullOrWhiteSpace(routeName))
                {
                    link = htmlHelper.RouteLink(text, routeName, newValues).ToHtmlString();
                }
                else
                {
                    actionName     = actionName ?? values["action"].ToString();
                    controllerName = controllerName ?? values["controller"].ToString();

                    IDictionary <string, object> htmlAttrtibutes = new Dictionary <string, object>();
                    htmlAttrtibutes.Add("class", className);

                    if (string.IsNullOrWhiteSpace(className))
                    {
                        link = htmlHelper.ActionLink(text, actionName, controllerName, newValues, null).ToHtmlString();
                    }
                    else
                    {
                        link = htmlHelper.ActionLink(text, actionName, controllerName, newValues, htmlAttrtibutes).ToHtmlString();
                    }
                }

                return(string.Concat(" ", link));
            };

            StringBuilder pagerHtml = new StringBuilder();

            if (pageCount > 1)
            {
                pagerHtml.Append("<div class=\"page-navigation Noprint\">");

                double half = Math.Ceiling(Convert.ToDouble(Convert.ToDouble(noOfPageToShow) / 2));

                int start = Convert.ToInt32((currentPage > half) ? Math.Max(Math.Min((currentPage - half), (pageCount - noOfPageToShow)), 0) : 0);
                int end   = Convert.ToInt32((currentPage > half) ? Math.Min(currentPage + half, pageCount) : Math.Min(noOfPageToShow, pageCount));

                pagerHtml.Append(currentPage > 1 ? getPageLink("上一页", currentPage - 1, "pre") : " <span class=\"pre\">上一页</span>");

                if (start > 0)
                {
                    int startingEnd = Math.Min(noOfPageInEdge, start);

                    for (int i = 0; i < startingEnd; i++)
                    {
                        int pageNo = i + 1;

                        pagerHtml.Append(getPageLink(pageNo.ToString(CultureInfo.CurrentCulture), pageNo, string.Empty));
                    }

                    if (noOfPageInEdge < start)
                    {
                        pagerHtml.Append(@"<span class=""etc"">...</span>");
                    }
                }

                for (int i = start; i < end; i++)
                {
                    int pageNo = i + 1;

                    pagerHtml.Append(pageNo == currentPage ? " <a class=\"now\">{0}</a>".FormatWith(pageNo) : getPageLink(pageNo.ToString(CultureInfo.CurrentCulture), pageNo, string.Empty));
                }

                if (end < pageCount)
                {
                    if ((pageCount - noOfPageInEdge) > end)
                    {
                        pagerHtml.Append(@"<span class=""etc"">...</span>");
                    }

                    int endingStart = Math.Max(pageCount - noOfPageInEdge, end);

                    for (int i = endingStart; i < pageCount; i++)
                    {
                        int pageNo = i + 1;
                        pagerHtml.Append(getPageLink(pageNo.ToString(CultureInfo.CurrentCulture), pageNo, string.Empty));
                    }
                }

                pagerHtml.Append(currentPage < pageCount ? getPageLink("下一页", currentPage + 1, "next") : " <span class=\"next\">下一页</span>");

                pagerHtml.Append(@"<span class=""go-page"">到第<input type=""textbox"" class=""pageText"" maxNum=""100"" value=""{0}"" />页 <input type=""button"" class=""view pagerbutton"" value=""确定"" /></span>".FormatWith(currentPage));

                pagerHtml.Append("</div>");
            }

            return(new HtmlString(pagerHtml.ToString()));
        }
Example #17
0
        public static MvcHtmlString ActionLink <TController>(this HtmlHelper helper, Expression <Action <TController> > action, string linkText, object htmlAttributes) where TController : Controller
        {
            RouteValueDictionary routingValues = ExpressionHelper.GetRouteValuesFromExpression(action);

            return(helper.RouteLink(linkText, routingValues, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)));
        }
Example #18
0
        public void NullOrEmptyStringParameterThrows()
        {
            // Arrange
            HtmlHelper htmlHelper = MvcHelper.GetHtmlHelper();
            Func <Action, GenericDelegate> Wrap = action => new GenericDelegate(() => action());
            var tests = new[] {
                // ActionLink(string linkText, string actionName)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.ActionLink(String.Empty, "actionName")) },

                // ActionLink(string linkText, string actionName, object routeValues, object htmlAttributes)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.ActionLink(String.Empty, "actionName", new Object(), null /* htmlAttributes */)) },

                // ActionLink(string linkText, string actionName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.ActionLink(String.Empty, "actionName", new RouteValueDictionary(), new RouteValueDictionary())) },

                // ActionLink(string linkText, string actionName, string controllerName)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.ActionLink(String.Empty, "actionName", "controllerName")) },

                // ActionLink(string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.ActionLink(String.Empty, "actionName", "controllerName", new Object(), null /* htmlAttributes */)) },

                // ActionLink(string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.ActionLink(String.Empty, "actionName", "controllerName", new RouteValueDictionary(), new RouteValueDictionary())) },

                // ActionLink(string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.ActionLink(String.Empty, "actionName", "controllerName", null, null, null, new RouteValueDictionary(), new RouteValueDictionary())) },

                // RouteLink(string linkText, object routeValues, object htmlAttributes)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.RouteLink(String.Empty, new Object(), null /* htmlAttributes */)) },

                // RouteLink(string linkText, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.RouteLink(String.Empty, new RouteValueDictionary(), new RouteValueDictionary())) },

                // RouteLink(string linkText, string routeName, object routeValues)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.RouteLink(String.Empty, "routeName", null /* routeValues */)) },

                // RouteLink(string linkText, string routeName, RouteValueDictionary routeValues)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.RouteLink(String.Empty, "routeName", new RouteValueDictionary() /* routeValues */)) },

                // RouteLink(string linkText, string routeName)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.RouteLink(String.Empty, (string)null /* routeName */)) },

                // RouteLink(string linkText, object routeValues)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.RouteLink(String.Empty, (object)null /* routeValues */)) },

                // RouteLink(string linkText, RouteValueDictionary routeValues)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.RouteLink(String.Empty, new RouteValueDictionary() /* routeValues */)) },

                // RouteLink(string linkText, string routeName, object routeValues, object htmlAttributes)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.RouteLink(String.Empty, "routeName", new Object(), null /* htmlAttributes */)) },

                // RouteLink(string linkText, string routeName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.RouteLink(String.Empty, "routeName", new RouteValueDictionary(), new RouteValueDictionary())) },

                // RouteLink(string linkText, string routeName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
                new { Parameter = "linkText", Action = Wrap(() => htmlHelper.RouteLink(String.Empty, "routeName", null, null, null, new RouteValueDictionary(), new RouteValueDictionary())) },
            };

            // Act & Assert
            foreach (var test in tests)
            {
                ExceptionHelper.ExpectArgumentExceptionNullOrEmpty(test.Action, test.Parameter);
            }
        }
Example #19
0
        //we have two pagers:
        //The first one can have custom routes
        //The second one just adds query string parameter
        public static MvcHtmlString Pager <TModel>(this HtmlHelper <TModel> html, PagerModel model)
        {
            if (model.TotalRecords == 0)
            {
                return(null);
            }

            var localizationService = EngineContext.Current.Resolve <ILocalizationService>();

            var links = new StringBuilder();

            if (model.ShowTotalSummary && (model.TotalPages > 0))
            {
                links.Append("<li>");
                links.Append(string.Format(model.CurrentPageText, model.PageIndex + 1, model.TotalPages, model.TotalRecords));
                links.Append("</li>");
            }
            if (model.ShowPagerItems && (model.TotalPages > 1))
            {
                if (model.ShowFirst)
                {
                    if ((model.PageIndex >= 3) && (model.TotalPages > model.IndividualPagesDisplayedCount))
                    {
                        //if (model.ShowIndividualPages)
                        //{
                        //    links.Append("&nbsp;");
                        //}

                        model.RouteValues.page = 1;

                        links.Append("<li>");
                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.FirstButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.FirstPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.FirstButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.FirstPageTitle") }));
                        }
                        links.Append("</li>");

                        //if ((model.ShowIndividualPages || (model.ShowPrevious && (model.PageIndex > 0))) || model.ShowLast)
                        //{
                        //    links.Append("&nbsp;...&nbsp;");
                        //}
                    }
                }
                if (model.ShowPrevious)
                {
                    if (model.PageIndex > 0)
                    {
                        model.RouteValues.page = (model.PageIndex);

                        links.Append("<li>");
                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.PreviousButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.PreviousPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.PreviousButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.PreviousPageTitle") }));
                        }
                        links.Append("</li>");
                        //if ((model.ShowIndividualPages || model.ShowLast) || (model.ShowNext && ((model.PageIndex + 1) < model.TotalPages)))
                        //{
                        //    links.Append("&nbsp;");
                        //}
                    }
                }
                if (model.ShowIndividualPages)
                {
                    int firstIndividualPageIndex = model.GetFirstIndividualPageIndex();
                    int lastIndividualPageIndex  = model.GetLastIndividualPageIndex();
                    for (int i = firstIndividualPageIndex; i <= lastIndividualPageIndex; i++)
                    {
                        if (model.PageIndex == i)
                        {
                            links.AppendFormat("<li><span>{0}</span></li>", (i + 1).ToString());
                        }
                        else
                        {
                            model.RouteValues.page = (i + 1);

                            links.Append("<li>");
                            if (model.UseRouteLinks)
                            {
                                links.Append(html.RouteLink((i + 1).ToString(), model.RouteActionName, (object)model.RouteValues, new { title = String.Format(localizationService.GetResource("Pager.PageLinkTitle").ToString(), (i + 1).ToString()) }));
                            }
                            else
                            {
                                links.Append(html.ActionLink((i + 1).ToString(), model.RouteActionName, (object)model.RouteValues, new { title = String.Format(localizationService.GetResource("Pager.PageLinkTitle").ToString(), (i + 1).ToString()) }));
                            }
                            links.Append("</li>");
                        }
                        //if (i < lastIndividualPageIndex)
                        //{
                        //    links.Append("&nbsp;");
                        //}
                    }
                }
                if (model.ShowNext)
                {
                    if ((model.PageIndex + 1) < model.TotalPages)
                    {
                        //if (model.ShowIndividualPages)
                        //{
                        //    links.Append("&nbsp;");
                        //}

                        model.RouteValues.page = (model.PageIndex + 2);

                        links.Append("<li>");
                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.NextButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.NextPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.NextButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.NextPageTitle") }));
                        }
                        links.Append("</li>");
                    }
                }
                if (model.ShowLast)
                {
                    if (((model.PageIndex + 3) < model.TotalPages) && (model.TotalPages > model.IndividualPagesDisplayedCount))
                    {
                        //if (model.ShowIndividualPages || (model.ShowNext && ((model.PageIndex + 1) < model.TotalPages)))
                        //{
                        //    links.Append("&nbsp;...&nbsp;");
                        //}

                        model.RouteValues.page = model.TotalPages;

                        links.Append("<li>");
                        if (model.UseRouteLinks)
                        {
                            links.Append(html.RouteLink(model.LastButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.LastPageTitle") }));
                        }
                        else
                        {
                            links.Append(html.ActionLink(model.LastButtonText, model.RouteActionName, (object)model.RouteValues, new { title = localizationService.GetResource("Pager.LastPageTitle") }));
                        }
                        links.Append("</li>");
                    }
                }
            }
            var result = links.ToString();

            if (!String.IsNullOrEmpty(result))
            {
                result = "<ul>" + result + "</ul>";
            }
            return(MvcHtmlString.Create(result));
        }
Example #20
0
        public static HtmlString Pager(this HtmlHelper html, string currentPageStr, int pageSize, int totalCount, Dictionary <string, int> paramDict = null)
        {
            var queryString = html.ViewContext.HttpContext.Request.QueryString;
            int currentPage = 1;                                                  //当前页

            int.TryParse(queryString[currentPageStr], out currentPage);           //与相应的QueryString绑定
            var totalPages = Math.Max((totalCount + pageSize - 1) / pageSize, 1); //总页数
            var dict       = new RouteValueDictionary(html.ViewContext.RouteData.Values);

            var output = new StringBuilder();

            foreach (string key in queryString.Keys)
            {
                if (queryString[key] != null && !string.IsNullOrEmpty(key))
                {
                    dict[key] = queryString[key];
                }
            }

            if (paramDict != null)
            {
                foreach (var item in paramDict)
                {
                    dict[item.Key] = item.Value;
                }
            }

            //页码小于1直接设置为1
            if (currentPage <= 1)
            {
                currentPage = 1;
            }

            if (totalPages > 1)
            {
                if (currentPage != 1)
                {//处理首页连接
                    dict["p"] = 1;
                    output.AppendFormat("{0} ", html.RouteLink("首页", dict));
                }
                if (currentPage > 1)
                {//处理上一页的连接
                    dict["p"] = currentPage - 1;
                    output.Append(html.RouteLink("上一页", dict));
                }
                else
                {
                    output.Append("上一页");
                }
                output.Append(" ");
                int currint = 5;
                for (int i = 0; i <= 10; i++)
                {//一共最多显示10个页码,前面5个,后面5个
                    if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages)
                    {
                        if (currint == i)
                        {//当前页处理
                            output.Append(string.Format("[{0}]", currentPage));
                        }
                        else
                        {//一般页处理
                            dict["p"] = currentPage + i - currint;
                            output.Append(html.RouteLink((currentPage + i - currint).ToString(), dict));
                        }
                    }
                    output.Append(" ");
                }
                if (currentPage < totalPages)
                {//处理下一页的链接
                    dict["p"] = currentPage + 1;
                    output.Append(html.RouteLink("下一页", dict));
                }
                else
                {
                    output.Append("下一页");
                }
                output.Append(" ");
                if (currentPage != totalPages)
                {
                    dict["p"] = totalPages;
                    output.Append(html.RouteLink("末页", dict));
                }
                output.Append(" ");
            }
            output.AppendFormat("{0} / {1}", currentPage, totalPages);//这个统计加不加都行

            return(new HtmlString(output.ToString()));
        }
Example #21
0
 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, ActionResult result, object htmlAttributes, string protocol, string hostName, string fragment)
 {
     return(htmlHelper.RouteLink(linkText, routeName, result, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), protocol, hostName, fragment));
 }
Example #22
0
        public static MvcHtmlString MvcSimplePager(this HtmlHelper html, int pageSize, int totalCount, bool showNumberLink)
        {
            var queryString = html.ViewContext.HttpContext.Request.QueryString;

            int currentPage = 1;

            var totalpages = Math.Max((totalCount + pageSize - 1) / pageSize, 1);

            var routeValueDict = new RouteValueDictionary(html.ViewContext.RouteData.Values);

            var _renderPager = new StringBuilder();

            if (!string.IsNullOrEmpty(queryString.Get(currentPageStr)))
            {
                foreach (string key in queryString.Keys)
                {
                    if (queryString[key] != null && !string.IsNullOrEmpty(key))
                    {
                        routeValueDict[key] = queryString[key];
                    }
                }
                int.TryParse(queryString[currentPageStr], out currentPage);
            }
            else
            {
                if (routeValueDict.ContainsKey(currentPageStr))
                {
                    int.TryParse(routeValueDict[currentPageStr].ToString(), out currentPage);
                }
            }

            foreach (string key in queryString.Keys)
            {
                routeValueDict[key] = queryString[key];
            }

            if (currentPage <= 0)
            {
                currentPage = 1;
            }

            string emptyAtagFormat = "<a href=\"#\" style=\"cursor:pointer;\">{0}</a>";

            if (totalpages == 1)
            {
                _renderPager.AppendFormat(emptyAtagFormat, "第一頁");
                _renderPager.AppendFormat(emptyAtagFormat, "上一頁");
                _renderPager.AppendFormat(emptyAtagFormat, "下一頁");
                _renderPager.AppendFormat(emptyAtagFormat, "最後一頁");
            }
            else if (totalpages > 1)
            {
                if (currentPage != 1)
                {
                    routeValueDict[currentPageStr] = 1;
                    _renderPager.Append(html.RouteLink("第一頁", routeValueDict));
                }
                else
                {
                    _renderPager.AppendFormat(emptyAtagFormat, "第一頁");
                }

                if (currentPage > 1)
                {
                    routeValueDict[currentPageStr] = currentPage - 1;
                    _renderPager.Append(html.RouteLink("上一頁", routeValueDict));
                }
                else
                {
                    _renderPager.AppendFormat(emptyAtagFormat, "上一頁");
                }
                #region 顯示頁數連結

                if (showNumberLink)
                {
                    var       pageCount           = (int)Math.Ceiling(totalCount / (double)pageSize);
                    const int nrOfPagesToDispolay = 10;

                    var start = 1;
                    var end   = pageCount;

                    if (pageCount > nrOfPagesToDispolay)
                    {
                        var middle = (int)Math.Ceiling(nrOfPagesToDispolay / 2d) - 1;
                        var below  = currentPage - middle;
                        var above  = currentPage + middle;

                        if (below < 4)
                        {
                            above = nrOfPagesToDispolay;
                            below = 1;
                        }
                        else if (above > (pageCount - 4))
                        {
                            above = pageCount;
                            below = pageCount - nrOfPagesToDispolay;
                        }

                        start = below;
                        end   = above;
                    }

                    if (start > 3)
                    {
                        routeValueDict[currentPageStr] = "1";
                        _renderPager.Append(html.RouteLink("1", routeValueDict));

                        routeValueDict[currentPageStr] = "2";
                        _renderPager.Append(html.RouteLink("2", routeValueDict));

                        _renderPager.Append("...");
                    }

                    for (int i = start; i <= end; i++)
                    {
                        if (i == currentPage || (currentPage <= 0 && i == 0))
                        {
                            _renderPager.AppendFormat("<span class=\"current\">{0}</span>", i);
                        }
                        else
                        {
                            routeValueDict[currentPageStr] = i.ToString();
                            _renderPager.Append(html.RouteLink(i.ToString(), routeValueDict));
                        }
                    }

                    if (end < (pageCount - 3))
                    {
                        _renderPager.Append("...");

                        routeValueDict[currentPageStr] = (pageCount - 1).ToString();
                        _renderPager.Append(html.RouteLink((pageCount - 1).ToString(), routeValueDict));

                        routeValueDict[currentPageStr] = pageCount.ToString();
                        _renderPager.Append(html.RouteLink(pageCount.ToString(), routeValueDict));
                    }
                }
                #endregion

                if (currentPage < totalpages)
                {
                    routeValueDict[currentPageStr] = currentPage + 1;
                    _renderPager.Append(html.RouteLink("下一頁", routeValueDict));
                }
                else
                {
                    _renderPager.AppendFormat(emptyAtagFormat, "下一頁");
                }

                if (currentPage != totalpages)
                {
                    routeValueDict[currentPageStr] = totalpages;
                    _renderPager.Append(html.RouteLink("最後一頁", routeValueDict));
                }
                else
                {
                    _renderPager.AppendFormat(emptyAtagFormat, "最後一頁");
                }
            }

            _renderPager.AppendFormat("第 {0} 頁 / 共 {0} 頁 共 {2} 筆", currentPage, totalpages, totalCount);

            return(new MvcHtmlString(_renderPager.ToString()));
        }
Example #23
0
 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, string routeName, ActionResult result, IDictionary <string, object> htmlAttributes, string protocol, string hostName)
 {
     return(htmlHelper.RouteLink(linkText, routeName, result, htmlAttributes, protocol, hostName, null));
 }
 public static string ConferenceLink(this HtmlHelper html, ConferenceInput conferenceInput)
 {
     return(html.RouteLink(conferenceInput.Name, "conferencedefault",
                           new { controller = "conference", action = "index", conferenceKey = conferenceInput.Key }).ToString());
 }
Example #25
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="html"></param>
        /// <param name="option"></param>
        /// <param name="builder"></param>
        private static void CreatePageLink(HtmlHelper html,
            PagingOptions option, StringBuilder builder)
        {
            var routeDict = GetRouteValueDictionary(html);
            routeDict.Remove(option.PageSegmentName);

            IDictionary<string, object> pageLinkHtmlAttributes =
                AnonymousTypeTools.GetDictionary(option.PageLinkHtmlAttributes);
            IDictionary<string, object> currentPageLinkHtmlAttributes =
                (option.CurrentPageLinkHtmlAttributes == null ? pageLinkHtmlAttributes :
                AnonymousTypeTools.GetDictionary(option.CurrentPageLinkHtmlAttributes));
            IDictionary<string, object> firstLastLinkHtmlAttributes =
                (option.FirstLastLinkHtmlAttributes == null ? pageLinkHtmlAttributes :
                AnonymousTypeTools.GetDictionary(option.FirstLastLinkHtmlAttributes));

            if (option.IncludeQueryStringForPage1)
                routeDict[option.PageSegmentName] = 1;

            builder.Append(html.RouteLink(option.FirstButtonTitle,
                routeDict, firstLastLinkHtmlAttributes));

            int count = option.MaxPageDisplay / 2;
            int prePage = Math.Max(option.CurrentPage - count, 1);
            count = option.MaxPageDisplay - 1 - option.CurrentPage + prePage;
            int lastPage = Math.Min(option.CurrentPage + count, option.TotalPage);
            count = count - lastPage + option.CurrentPage;
            prePage = Math.Max(prePage - count, 1);

            IDictionary<string, object> htmlDict;
            for (int page = prePage; page <= lastPage; page++)
            {
                if (page == option.CurrentPage)
                    htmlDict = currentPageLinkHtmlAttributes;
                else htmlDict = pageLinkHtmlAttributes;
                if (page > 1)
                    routeDict[option.PageSegmentName] = page;
                builder.Append(html.RouteLink(page.ToString(),
                    routeDict, htmlDict));
            }

            if (option.TotalPage > 1)
                routeDict[option.PageSegmentName] = option.TotalPage;
            builder.Append(html.RouteLink(option.LastButtonTitle,
                routeDict, firstLastLinkHtmlAttributes));
        }
Example #26
0
        /// <summary>
        /// 分页Pager显示
        /// </summary>
        /// <param name="html"></param>
        /// <param name="currentPageStr">标识当前页码的QueryStringKey</param>
        /// <param name="pageSize">每页显示</param>
        /// <param name="totalCount">总数据量</param>
        /// <returns></returns>
        public static string Pager(this HtmlHelper html, string currentPageStr, int pageSize, int totalCount)
        {
            var queryString = html.ViewContext.HttpContext.Request.QueryString;
            int currentPage = 1;                                                   //当前页
            var totalPages  = Math.Max((totalCount + pageSize - 1) / pageSize, 1); //总页数
            var dict        = new System.Web.Routing.RouteValueDictionary(html.ViewContext.RouteData.Values);
            var output      = new StringBuilder();

            output.Append("<ul class=\"pagination\">");
            //output.AppendFormat("<li><a href=\"#\">{0}</a></li>", totalCount);
            if (!string.IsNullOrEmpty(queryString[currentPageStr]))
            {
                //与相应的QueryString绑定
                foreach (string key in queryString.Keys)
                {
                    if (queryString[key] != null && !string.IsNullOrEmpty(key))
                    {
                        dict[key] = queryString[key];
                    }
                }
                int.TryParse(queryString[currentPageStr], out currentPage);
            }
            else
            {
                //获取 ~/Page/{page number} 的页号参数
                if (dict.ContainsKey(currentPageStr))
                {
                    int.TryParse(dict[currentPageStr].ToString(), out currentPage);
                }
            }

            //保留查询字符到下一页
            foreach (string key in queryString.Keys)
            {
                dict[key] = queryString[key];
            }

            //如果有需要,保留表单值到下一页 (我暂时不需要, 所以注释掉)
            //var formValue = html.ViewContext.HttpContext.Request.Form;
            //foreach (string key in formValue.Keys)
            //    if (formValue[key] != null && !string.IsNullOrEmpty(key))
            //        dict[key] = formValue[key];

            if (currentPage <= 0)
            {
                currentPage = 1;
            }
            if (totalPages > 1)
            {
                if (currentPage != 1)
                {
                    //处理首页连接
                    dict[currentPageStr] = 1;
                    output.AppendFormat("<li>{0}</li>", html.RouteLink("首页", dict));
                }
                if (currentPage > 1)
                {
                    //处理上一页的连接
                    dict[currentPageStr] = currentPage - 1;
                    output.AppendFormat("<li>{0}</li>", html.RouteLink("<<", dict));
                }
                int currint = 5;
                for (int i = 0; i <= 10; i++)
                {
                    //一共最多显示10个页码,前面5个,后面5个
                    if ((currentPage + i - currint) >= 1 && (currentPage + i - currint) <= totalPages)
                    {
                        if (currint == i)
                        {
                            //当前页处理
                            output.Append(string.Format("<li class=\"active\"><a href=\"#\">{0}</a></li>", currentPage));
                        }
                        else
                        {
                            //一般页处理
                            dict[currentPageStr] = currentPage + i - currint;
                            output.AppendFormat("<li>{0}</li>", html.RouteLink((currentPage + i - currint).ToString(), dict));
                        }
                    }
                }
                if (currentPage < totalPages)
                {
                    //处理下一页的链接
                    dict[currentPageStr] = currentPage + 1;
                    output.AppendFormat("<li>{0}</li>", html.RouteLink(">>", dict));
                }
                if (currentPage != totalPages)
                {
                    dict[currentPageStr] = totalPages;
                    output.AppendFormat("<li>{0}</li>", html.RouteLink("末页", dict));
                }
            }
            //  output.AppendFormat("<li>{0} / {1}</li>", currentPage, totalPages);//这个统计加不加都行
            output.Append("</ul>");
            return(output.ToString());
        }
Example #27
0
        public override string Render(HtmlHelper helper)
        {
            StringBuilder str = new StringBuilder();

            if (LastPage <= 1)
            {
                return "";
            }

            // First block: Previous link
            FillPageData(helper);
            if (Page <= 0)
            {
                //str.Append(PreviousText);
            }
            else
            {
                CurrentRoute["Page"] = Page - 1;
                str.Append(helper.RouteLink(PreviousText, CurrentRoute));
            }
            str.Append(" ");
            int cpage = 0;

            // Second block: first few links
            while (cpage < PagesPerBlock)
            {
                if (cpage >= LastPage) break;
                CurrentRoute["Page"] = cpage;
                if (cpage == Page)
                {
                    str.Append(cpage + 1);
                } else
                {
                    str.Append(helper.RouteLink((cpage+1).ToString(), CurrentRoute));
                }
                str.Append(" ");
                cpage++;
            }
            // Third block: middle links
            if (cpage < Page - PagesPerBlock + 1)
            {
                str.Append("... ");
                cpage = Page - PagesPerBlock + 1;
            }
            while (cpage < Page+PagesPerBlock)
            {
                if (cpage >= LastPage) break;
                CurrentRoute["Page"] = cpage;
                if (cpage == Page)
                {
                    str.Append(cpage + 1);
                }
                else
                {
                    str.Append(helper.RouteLink((cpage + 1).ToString(), CurrentRoute));
                }
                str.Append(" ");
                cpage++;
            }

            // Fourth block: end links
            if (cpage < LastPage - PagesPerBlock + 1)
            {
                str.Append("... ");
                cpage = LastPage - PagesPerBlock + 1;
            }
            while (cpage < LastPage)
            {
                CurrentRoute["Page"] = cpage;
                if (cpage == Page)
                {
                    str.Append(cpage + 1);
                }
                else
                {
                    str.Append(helper.RouteLink((cpage + 1).ToString(), CurrentRoute));
                }
                str.Append(" ");
                cpage++;
            }
            // Fifth block: Next link
            if (Page >= LastPage-1)
            {
                //str.Append(NextText);
            }
            else
            {
                CurrentRoute["Page"] = Page + 1;
                str.Append(helper.RouteLink(NextText, CurrentRoute));
            }
            return str.ToString();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
        /// <param name="linkText">The inner text of the anchor element.</param>
        /// <param name="actionName"></param>
        /// <param name="controllerName"></param>
        /// <param name="protocol">The protocol for the URL, such as "http" or "https".</param>
        /// <param name="hostName">The host name for the URL.</param>
        /// <param name="fragment">The URL fragment name (the anchor name).</param>
        /// <param name="routeValues">An object that contains the parameters for a route.</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
        /// <returns>An anchor element (a element).</returns>
        public static MvcHtmlString MvcActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary <string, object> htmlAttributes)
        {
            var routeValuesDictionary = MergeRouteValues(actionName, controllerName, routeValues);

            return(htmlHelper.RouteLink(linkText, MvcRouteName ?? DefaultRouteName, protocol, hostName, fragment, routeValuesDictionary, htmlAttributes));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
        /// <param name="linkText">The inner text of the anchor element.</param>
        /// <param name="actionName">The name of the action.</param>
        /// <param name="routeValues">An object that contains the parameters for a route.
        /// The parameters are retrieved through reflection by examining the properties of the object.
        /// The object is typically created by using object initializer syntax.</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes for the element.
        /// The attributes are retrieved through reflection by examining the properties of the object.
        /// The object is typically created by using object initializer syntax.</param>
        /// <returns>An anchor element (a element).</returns>
        public static MvcHtmlString MvcActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes)
        {
            var routeValuesDictionary = MergeRouteValues(actionName, null, routeValues);

            return(htmlHelper.RouteLink(linkText, MvcRouteName ?? DefaultRouteName, routeValuesDictionary, GetHtmlAttributes(htmlAttributes)));
        }
Example #30
0
 public static MvcHtmlString RouteLink(this HtmlHelper htmlHelper, string linkText, Hash routeValues, Hash htmlAttributes)
 {
     return(htmlHelper.RouteLink(linkText, HashHelper.ToRouteValueDictionary(routeValues), HashHelper.ToRouteValueDictionary(htmlAttributes)));
 }