本文整理汇总了C#中TagBuilder.AddAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# TagBuilder.AddAttributes方法的具体用法?C# TagBuilder.AddAttributes怎么用?C# TagBuilder.AddAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TagBuilder
的用法示例。
在下文中一共展示了TagBuilder.AddAttributes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NavigationLink
public static string NavigationLink(this HtmlHelper htmlHelper, string url, string innerHtml, object htmlAttributes, string wrapperElement, bool markSelectedWhenActive)
{
if (string.IsNullOrEmpty(url)) return string.Empty;
var tagBuilder = new TagBuilder("a");
tagBuilder.MergeAttribute("href", url);
tagBuilder.AddAttributes(htmlAttributes);
if (UrlMatchesCurrentPath(url, htmlHelper) && string.IsNullOrEmpty(wrapperElement))
{
tagBuilder.MergeAttribute("class", "selected");
}
tagBuilder.InnerHtml = innerHtml;
var navigationLink = tagBuilder.ToString(TagRenderMode.Normal);
if (!string.IsNullOrEmpty(wrapperElement))
{
var wrapperElementBuilder = new TagBuilder(wrapperElement);
if (UrlMatchesCurrentPath(url, htmlHelper))
{
wrapperElementBuilder.MergeAttribute("class", "selected");
}
wrapperElementBuilder.InnerHtml = navigationLink;
navigationLink = wrapperElementBuilder.ToString(TagRenderMode.Normal);
}
return navigationLink;
}
示例2: Navigation
public static MvcHtmlString Navigation(this HtmlHelper htmlHelper, Func<IEnumerable<MvcHtmlString>> items, object attributes = null, string listElement = "ul")
{
var nonEmptyItems = items().Where(x => !String.IsNullOrWhiteSpace(x.ToHtmlString()));
if (nonEmptyItems.Any() == false) return MvcHtmlString.Empty;
var innerHtml = nonEmptyItems.Aggregate(String.Empty, (current, item) => String.Concat(current, item.ToHtmlString()));
var list = new TagBuilder(listElement);
list.AddAttributes(attributes);
list.InnerHtml = innerHtml;
return MvcHtmlString.Create(list.ToString());
}
示例3: NavigationLink
public static MvcHtmlString NavigationLink(this HtmlHelper htmlHelper,
string url,
string innerHtml,
string wrapperElement = null,
object htmlAttributes = null,
bool markSelectedWhenActive = true,
bool markSelectedWhenExactMatchOnly = false,
bool alwaysDisplayInnerHtml = false
)
{
if (string.IsNullOrEmpty(url))
return alwaysDisplayInnerHtml ? MvcHtmlString.Create(innerHtml) : MvcHtmlString.Empty;
var tagBuilder = new TagBuilder("a");
tagBuilder.MergeAttribute("href", url);
tagBuilder.AddAttributes(htmlAttributes);
Func<string, HtmlHelper, bool> urlIsCurrentPathMatch = UrlMatchesCurrentPath;
if (markSelectedWhenExactMatchOnly) urlIsCurrentPathMatch = UrlMatchesCurrentPathExactly;
if (markSelectedWhenActive && urlIsCurrentPathMatch(url, htmlHelper) && string.IsNullOrEmpty(wrapperElement))
tagBuilder.InnerHtml = String.Format("<strong>{0}</strong>", innerHtml);
else
tagBuilder.InnerHtml = innerHtml;
var navigationLink = tagBuilder.ToString(TagRenderMode.Normal);
if (!string.IsNullOrEmpty(wrapperElement))
{
var wrapperElementBuilder = new TagBuilder(wrapperElement);
if (markSelectedWhenActive && urlIsCurrentPathMatch(url, htmlHelper))
wrapperElementBuilder.InnerHtml = String.Format("<strong>{0}</strong>", navigationLink);
else
wrapperElementBuilder.InnerHtml = navigationLink;
navigationLink = wrapperElementBuilder.ToString(TagRenderMode.Normal);
}
return MvcHtmlString.Create(navigationLink);
}