当前位置: 首页>>代码示例>>C#>>正文


C# TagBuilder.AddAttributes方法代码示例

本文整理汇总了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;
        }
开发者ID:pvivera,项目名称:FluentSecurity,代码行数:27,代码来源:HtmlExtensions.cs

示例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());
        }
开发者ID:kristofferahl,项目名称:FluentSecurity-Website,代码行数:13,代码来源:HtmlHelperExtensions.cs

示例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);
        }
开发者ID:kristofferahl,项目名称:FluentSecurity-Website,代码行数:39,代码来源:HtmlHelperExtensions.cs


注:本文中的TagBuilder.AddAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。