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


C# TagBuilder.AddCssClass方法代码示例

本文整理汇总了C#中TagBuilder.AddCssClass方法的典型用法代码示例。如果您正苦于以下问题:C# TagBuilder.AddCssClass方法的具体用法?C# TagBuilder.AddCssClass怎么用?C# TagBuilder.AddCssClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TagBuilder的用法示例。


在下文中一共展示了TagBuilder.AddCssClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MenuItem

        public static string MenuItem(this HtmlHelper helper, string linkText, string actionName, string controllerName, string area)
        {
            if (Roles.IsUserInRole(ROLES.admin.ToString())
                || controllerName.Equals("Home")
                || controllerName.Equals("AccountTransactions")
                || controllerName.Equals("Message"))
            {

                var currentControllerName = (string)helper.ViewContext.RouteData.Values["controller"];
                var currentActionName = (string)helper.ViewContext.RouteData.Values["action"];

                var builder = new TagBuilder("li");

                builder.AddCssClass("ui-state-default ui-corner-top");

                // Add selected class
                if (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase))
                    builder.AddCssClass("ui-state-active");

                // Add link
                builder.InnerHtml = helper.ActionLink(linkText, actionName, controllerName, new { area = area }, null).ToHtmlString();

                // Render Tag Builder
                return builder.ToString(TagRenderMode.Normal);
            }
            return String.Empty;
        }
开发者ID:gamchantoi,项目名称:astra-contact-manager,代码行数:27,代码来源:MenuItemHelper.cs

示例2: AjaxLinkModalWindow

        public static MvcHtmlString AjaxLinkModalWindow(
            this HtmlHelper htmlHelper,
            string linkText,
            string targetUrl,
            string modalId,
            string targetId,
            string cssClass,
            string iconClass,
            string dataGet)
        {
            var builder = new TagBuilder("a");
            builder.SetInnerText(" " + linkText);
            builder.Attributes.Add("href", "#");
            builder.Attributes.Add("data-target-url", targetUrl);
            builder.Attributes.Add("data-target-id", targetId);
            builder.Attributes.Add("data-modal-id", modalId);
            builder.Attributes.Add("data-get", dataGet);
            builder.AddCssClass("ajax-link-modal-window");
            builder.AddCssClass(cssClass);
            var iconBuilder = new TagBuilder("i");
            iconBuilder.AddCssClass(iconClass);
            builder.InnerHtml += iconBuilder.ToString();

            return new MvcHtmlString(builder.ToString());
        }
开发者ID:RamanBut-Husaim,项目名称:TermWork-SignalRChat,代码行数:25,代码来源:HtmlHelpers.cs

示例3: ToHtmlString

        /// <summary>
        ///   Renders the div with formgroup class with some html controls inside
        /// </summary>
        /// <returns></returns>
        public string ToHtmlString()
        {
            var formGroup = new TagBuilder("div");
            formGroup.AddCssClass("form-group");

            if (!_fieldIsValid)
                formGroup.AddCssClass("error");

            switch (_type)
            {
                case FormGroupType.TextBoxLike:

                    formGroup.InnerHtml = _label + _input.ToHtmlString();
                    break;

                case FormGroupType.CheckBoxLike:

                    formGroup.InnerHtml = _label.ToHtmlString();
                    break;

                default:
                    break;
            }

            return formGroup.ToString();
        }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:30,代码来源:FormGroup.cs

示例4: NavigationListItemRouteLink

 public static MvcHtmlString NavigationListItemRouteLink(this HtmlHelper html, NamedRoute route)
 {
     var li = new TagBuilder("li")
         {
             InnerHtml = html.RouteLink(route.DisplayName, route.Name).ToString()
         };
     
     if (CurrentRouteMatchesName(html, route.Name))
     {
         li.AddCssClass("active");
     }
     if (route.Children.Count() > 0)
     {
         //TODO: create a UL of child routes here.
         li.AddCssClass("dropdown");
         li.InnerHtml = "<a href=\"#\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">" + route.DisplayName +"<b class=\"caret\"></b></a>";
         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();
         }
         //that would mean we need to make some quick
         
         li.InnerHtml = "<a href='#' class='dropdown-toggle' data-toggle='dropdown'>"+route.DisplayName + " <b class='caret'></b></a>" + ul.ToString();
         
     }
     return MvcHtmlString.Create(li.ToString(TagRenderMode.Normal));
 }
开发者ID:Olgish87,项目名称:RexKex.se,代码行数:32,代码来源:NavigationExtensions.cs

示例5: CreateElement

        public static MvcHtmlString CreateElement(this HtmlHelper htmlHelper)
        {
            var allHtml = new TagBuilder("span");

            for (int i = 1; i < 6; i++)
            {
                var divBuilder = new TagBuilder("div");
                var divTwoBuilder = new TagBuilder("div");
                var spanBuilder = new TagBuilder("span");
                var iBuilder = new TagBuilder("i");

                if (i == 5) divBuilder.AddCssClass("cssload-last-finger");
                else divBuilder.AddCssClass("cssload-finger cssload-finger-" + i);

                if (i == 5) divTwoBuilder.AddCssClass("cssload-last-finger-item");
                else divTwoBuilder.AddCssClass("cssload-finger-item");

                divTwoBuilder.InnerHtml += spanBuilder.ToString() + iBuilder.ToString();
                divBuilder.InnerHtml += divTwoBuilder.ToString();

                allHtml.InnerHtml += divBuilder;
            }

            return new MvcHtmlString(allHtml.ToString());
        }
开发者ID:AnnZanevskaya,项目名称:Project,代码行数:25,代码来源:LoadingHelper.cs

示例6: PageLinks

        public static MvcHtmlString PageLinks(this HtmlHelper html, PageInfo pageInfo, Func<int, string> pageUrl)
        {
            StringBuilder result = new StringBuilder();

            for (int i = 1; i <= pageInfo.TotalPages; i++)
            {
                TagBuilder tag = new TagBuilder("a");
                tag.MergeAttribute("href", pageUrl(i));
                tag.MergeAttribute("data-ajax-update", "#address-cursor-rows");
                tag.MergeAttribute("data-ajax-success", "OnSuccess");
                tag.MergeAttribute("data-ajax-mode", "replace");
                tag.MergeAttribute("data-ajax", "true");
                tag.InnerHtml = i.ToString();

                // если текущая страница, то выделяем ее, например, добавляя класс
                if (i == pageInfo.PageNumber)
                {
                    tag.AddCssClass("selected");
                    tag.AddCssClass("btn-primary");
                }
                tag.AddCssClass("btn btn-default");

                result.Append(tag.ToString());
            }

            return MvcHtmlString.Create(result.ToString());
        }
开发者ID:fedihor,项目名称:gmapa,代码行数:27,代码来源:PagingHelpers.cs

示例7: PageLinks

        public static MvcHtmlString PageLinks(this HtmlHelper html, 
            PagingInfo pagingInfo, 
            Func<int, string> pageUrl)
        {
            var result = new StringBuilder();

            for (int i = 0; i < pagingInfo.TotalPages; i++)
            {
                var pageNumber = i + 1;
                //build anchor
                var tag = new TagBuilder("a");
                //build the out goin url
                tag.MergeAttribute("href", pageUrl(pageNumber));
                tag.InnerHtml = pageNumber.ToString();
                if (pageNumber == pagingInfo.CurrentPage)
                {
                    //add bootstrap style
                    tag.AddCssClass("selected");
                    tag.AddCssClass("btn-primary");
                }
                else
                {
                    tag.AddCssClass("btn-default");
                }
                tag.AddCssClass("btn");

                result.Append(tag);
            }

            return MvcHtmlString.Create(result.ToString());
        }
开发者ID:naingyelin,项目名称:SportsStore,代码行数:31,代码来源:PagingHelpers.cs

示例8: ToHtmlString

        public override string ToHtmlString()
        {
            string innerText = Text ?? string.Empty;
            string fullName = Name;
            string tagName = TagName.HasValue() ? TagName.ToLower() : "span";

            var tagBuilder = new TagBuilder(tagName);
            if (Encode)
                tagBuilder.SetInnerText(innerText);
            else
                tagBuilder.InnerHtml = innerText;

            tagBuilder.MergeAttributes(HtmlAttributes);

            if (fullName.HasValue())
                tagBuilder.GenerateId(fullName);

            foreach (string cssClass in CssClasses)
                tagBuilder.AddCssClass(cssClass);

            if (CanWrite())
            {
                if (GrantedClass.HasValue())
                    tagBuilder.AddCssClass(GrantedClass);
            }
            else
            {
                if (DeniedClass.HasValue())
                    tagBuilder.AddCssClass(DeniedClass);
            }

            return tagBuilder.ToString(TagRenderMode.Normal);
        }
开发者ID:modulexcite,项目名称:FluentHtml,代码行数:33,代码来源:Element.cs

示例9: Panel

 public Panel(HtmlHelper helper, string templateName, params string[] classNames)
 {
     _helper = helper;
     _templateName = templateName;
     ViewContext context = helper.ViewContext;
     _builder = new TagBuilder("div");
     if (classNames == null || classNames.Length == 0)
     {
         classNames = new[] { "widget" };
     }
     var includeWidget = false;
     foreach (var cls in classNames)
     {
         if (cls == "widget")
         {
             includeWidget = true;
         }
         _builder.AddCssClass(cls);
     }
     if (!includeWidget)
     {
         _builder.AddCssClass("widget");
     }
     context.Writer.Write(_builder.ToString(TagRenderMode.StartTag));
     _context = context;
 }
开发者ID:luqizheng,项目名称:OrnamentFramework,代码行数:26,代码来源:Panel.cs

示例10: MenuItem

 public static MvcHtmlString MenuItem(this HtmlHelper htmlHelper, string text, string action, string controller, int? categoryId = null, string cssClasses = null)
 {
     var li = new TagBuilder("li");
     var routeData = htmlHelper.ViewContext.RouteData;
     var currentAction = routeData.GetRequiredString("action");
     var currentController = routeData.GetRequiredString("controller");
     if (string.Equals(currentAction, action, StringComparison.OrdinalIgnoreCase) &&
         string.Equals(currentController, controller, StringComparison.OrdinalIgnoreCase))
     {
         li.AddCssClass("active");
     }
     if (!string.IsNullOrEmpty(cssClasses))
     {
         li.AddCssClass(cssClasses);
     }
     if (categoryId != null)
     {
         li.InnerHtml = htmlHelper.ActionLink(text, action, controller,new { id = categoryId.Value },new {}).ToHtmlString();
     }
     else
     {
         li.InnerHtml = htmlHelper.ActionLink(text, action, controller).ToHtmlString();
     }
     return MvcHtmlString.Create(li.ToString());
 }
开发者ID:Icestorm0141,项目名称:portfolio,代码行数:25,代码来源:MenuExtensions.cs

示例11: CopyButton

        public static MvcHtmlString CopyButton(this HtmlHelper helper, string name, string actionName,
                                                 string controllerName, object routeValues,
                                                 object htmlAttributes)
        {
            var buttonBuilder = new TagBuilder("button");
            buttonBuilder.SetInnerText(name);
            buttonBuilder.AddCssClass("btn");
            buttonBuilder.AddCssClass("btn-success");
            buttonBuilder.Attributes.Add("id", "copyButton");

            var iBuilder = new TagBuilder("i");
            iBuilder.AddCssClass("icon-camera");
            iBuilder.AddCssClass("icon-white");
            buttonBuilder.InnerHtml = Environment.NewLine + iBuilder + Environment.NewLine + buttonBuilder.InnerHtml;

            var formBuilder = new TagBuilder("form");

            var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);

            var url = urlHelper.Action(actionName, controllerName, routeValues);

            url = QuerystringHelper.PropagateModal(url);

            formBuilder.Attributes.Add("action", url);
            formBuilder.Attributes.Add("method", "POST");
            formBuilder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            formBuilder.InnerHtml = Environment.NewLine + buttonBuilder;

            return new MvcHtmlString(formBuilder.ToString());
        }
开发者ID:avannini,项目名称:uisp-mobile,代码行数:30,代码来源:CopyButtonExtension.cs

示例12: BootstrapTextbox

        public static MvcHtmlString BootstrapTextbox(this HtmlHelper htmlHelper, MvcHtmlString htmlTextBox, string prepend, string append)
        {
            TagBuilder builder = new TagBuilder("div");

            if (!string.IsNullOrEmpty(prepend))
            {
                builder.AddCssClass("input-prepend");
                TagBuilder span = new TagBuilder("span");
                span.AddCssClass("add-on");
                span.InnerHtml += prepend;
                builder.InnerHtml += span;
            }

            builder.InnerHtml += htmlTextBox;

            if (!string.IsNullOrEmpty(append))
            {
                builder.AddCssClass("input-append");
                TagBuilder span = new TagBuilder("span");
                span.AddCssClass("add-on");
                span.InnerHtml += append;
                builder.InnerHtml += span;
            }

            return MvcHtmlString.Create(builder.ToString());
        }
开发者ID:jgennari,项目名称:Mvc.Bootstrap,代码行数:26,代码来源:Fields.cs

示例13: Result

        public static MvcHtmlString Result(this HtmlHelper html, string testName, bool isPassed, int result, int amountOfQuestions, int amountOfCorrectQuestions)
        {
            TagBuilder p = new TagBuilder("p");
            string innerText = "Тест \"" + testName + "\" ";
            TagBuilder span = new TagBuilder("span");
            if (isPassed)
            {
                span.AddCssClass("passed");
                span.InnerHtml = "успешно пройден!";
            }
            else
            {
                span.AddCssClass("failed");
                span.InnerHtml = "не пройден!";
            }

            innerText += span.ToString(TagRenderMode.Normal);

            p.InnerHtml = innerText;

            TagBuilder pRes = new TagBuilder("p");
            pRes.InnerHtml = "Правильных ответов: " + amountOfCorrectQuestions + "/" + amountOfQuestions + "(" + result + "%)";
            string res = p.ToString() + pRes.ToString();

            return MvcHtmlString.Create(res);
        }
开发者ID:timoshuck,项目名称:QuizSite,代码行数:26,代码来源:ResultHelper.cs

示例14: PageLinks

        public static MvcHtmlString PageLinks(this HtmlHelper html,
                                                PagingInfo pagingInfo,
                                                Func<int, string> pageUrl)
        {
            var result = new StringBuilder();

            for (int i = 1; i <= pagingInfo.TotalPages; i++)
            {
                var tag = new TagBuilder("a");
                tag.MergeAttribute("href", pageUrl(i));
                // Func<int, string>
                // int here is just the input type, 1 parameter
                // string is what is returned.
                // <a href="computedFunc pageUrl">

                tag.InnerHtml = i.ToString();
                //i

                if (i == pagingInfo.CurrentPage)
                {
                    tag.AddCssClass("selected");
                    tag.AddCssClass("btn-primary");
                }
                tag.AddCssClass("btn btn-default");
                result.Append(tag.ToString());
            }

            return MvcHtmlString.Create(result.ToString());
        }
开发者ID:necampanini,项目名称:mvcStack_practice_01,代码行数:29,代码来源:PagingHelpers.cs

示例15: ToHtmlString

        public string ToHtmlString()
        {
            TagBuilder buttonTag = new TagBuilder(Tag.ToString());

            buttonTag.AddCssClass("k-button k-button-icontext td-grid-button");
            if (CssClass.HasValue())
                buttonTag.AddCssClass(CssClass.Trim());

            if (Name.HasValue())
            {
                buttonTag.MergeAttribute("name", Name);
                buttonTag.GenerateId(Name);
            }

            if (Title.HasValue())
                buttonTag.MergeAttribute("title", Title);

            if (Tag == ButtonTag.a)
                buttonTag.MergeAttribute("href", Url.HasValue() ? Url : "javascript: void(0)");

            if (HtmlAttributes.Count > 0)
                buttonTag.MergeAttributes(HtmlAttributes);

            var imageTag = new TagBuilder("span");
            imageTag.AddCssClass("k-icon td-grid-button-image");
            if (ImageCssClass.HasValue())
                imageTag.AddCssClass(ImageCssClass);

            buttonTag.InnerHtml = imageTag.ToString();

            return buttonTag.ToString();
        }
开发者ID:nixeramus,项目名称:cts-project,代码行数:32,代码来源:ImageButton.cs


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