本文整理汇总了C#中HtmlHelper.RouteLink方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.RouteLink方法的具体用法?C# HtmlHelper.RouteLink怎么用?C# HtmlHelper.RouteLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper.RouteLink方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReleaseLink
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();
}
示例2: CreatorRouteLink
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);
}
示例3: BuildChildMenu
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();
}
示例4: Render
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();
}
示例5: CreatePageLink
/// <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));
}