本文整理汇总了C#中System.Web.Mvc.HtmlHelper.PageLink方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.PageLink方法的具体用法?C# HtmlHelper.PageLink怎么用?C# HtmlHelper.PageLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper.PageLink方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderSubNavigationLevel
private static void RenderSubNavigationLevel(
HtmlHelper helper,
ContentReference levelRootLink,
IEnumerable<ContentReference> path,
IContentLoader contentLoader)
{
//Retrieve and filter the pages on the current level
var children = contentLoader.GetChildren<PageData>(levelRootLink);
children = FilterForVisitor.Filter(children)
.OfType<PageData>()
.Where(x => x.VisibleInMenu);
if (!children.Any())
{
//There's nothing to render on this level so we abort
//in order not to write an empty ul element.
return;
}
var writer = helper.ViewContext.Writer;
//Open list element for the current level
writer.WriteLine("<ul class=\"nav\">");
//Project to an anonymous class in order to know
//the index of each page in the collection when
//iterating over it.
var indexedChildren = children
.Select((page, index) => new { index, page })
.ToList();
foreach (var levelItem in indexedChildren)
{
var page = levelItem.page;
var partOfCurrentBranch = path.Any(x =>
x.CompareToIgnoreWorkID(levelItem.page.ContentLink));
if (partOfCurrentBranch)
{
//We highlight pages that are part of the current branch,
//including the currently viewed page.
writer.WriteLine("<li class=\"active\">");
}
else
{
writer.WriteLine("<li>");
}
writer.WriteLine(helper.PageLink(page).ToHtmlString());
if (partOfCurrentBranch)
{
//The page is part of the current pages branch,
//so we render a level below it
RenderSubNavigationLevel(
helper,
page.ContentLink,
path,
contentLoader);
}
writer.WriteLine("</li>");
}
//Close list element
writer.WriteLine("</ul>");
}