當前位置: 首頁>>代碼示例>>C#>>正文


C# TagHelpers.TagHelperOutput類代碼示例

本文整理匯總了C#中Microsoft.AspNet.Razor.TagHelpers.TagHelperOutput的典型用法代碼示例。如果您正苦於以下問題:C# TagHelperOutput類的具體用法?C# TagHelperOutput怎麽用?C# TagHelperOutput使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TagHelperOutput類屬於Microsoft.AspNet.Razor.TagHelpers命名空間,在下文中一共展示了TagHelperOutput類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Process

 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     output.TagName = "p";
     output.Attributes["class"] = "example";
     output.PostContent.SetContent("Hello from the tag helper! ");
     output.PostContent.Append("Title sent in was: " + Title + " and Body: " + Body);
 }
開發者ID:LadyLizzy,項目名稱:mvc6-example,代碼行數:7,代碼來源:ExampleTagHelper.cs

示例2: Process

 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     if (HideIf)
     {
         output.SuppressOutput();
     }
 }
開發者ID:RR-Studio,項目名稱:RealEstateCrm,代碼行數:7,代碼來源:HideTagHelper.cs

示例3: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            StringBuilder sb = new StringBuilder();

            string menuUrl = _UrlHelper.Action(ActionName, ControllerName, new { Area = AreaName });

            if (string.IsNullOrEmpty(menuUrl))
                throw new InvalidOperationException(string.Format("Can not find URL for {0}.{1}", ControllerName, ActionName));

            output.TagName = "li";

            var a = new TagBuilder("a");
            a.MergeAttribute("href", $"{menuUrl}");
            a.MergeAttribute("title", MenuText);
            a.InnerHtml.Append(MenuText);

            var routeData = ViewContext.RouteData.Values;
            var currentController = routeData["controller"];
            var currentAction = routeData["action"];
            var currentArea = routeData.ContainsKey("area") ? routeData["area"] : string.Empty;

            if (string.Equals(ActionName, currentAction as string, StringComparison.OrdinalIgnoreCase)
                && string.Equals(ControllerName, currentController as string, StringComparison.OrdinalIgnoreCase)
                && string.Equals(AreaName, currentArea as string, StringComparison.OrdinalIgnoreCase))
            {
                output.Attributes.Add("class", "active");
            }

            output.Content.SetContent(a);
        }
開發者ID:AugustinasNomicas,項目名稱:BookingSystem,代碼行數:30,代碼來源:MenuLinkTagHelper.cs

示例4: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {

            output.TagName = "select";

            if (Disabled)
            {
                output.Attributes["disabled"] = "disabled";
            }


            var items = new StringBuilder();
            var cityList = DbContext.Cities.OrderBy(x => x.Name).ToList();

            items.Append("<option value=\"\">Все города</option>");
            foreach (var city in cityList)
            {
                if (city.Id == CityId)
                {
                    items.Append($"<option value=\"{city.Id}\" selected=\"true\">{city.Name}</option>");
                }
                else
                {
                    items.Append($"<option value=\"{city.Id}\">{city.Name}</option>");
                }
            }
        
            output.Content.SetHtmlContent(items.ToString());
            output.Attributes.Add("class", "ui fluid dropdown");
        }
開發者ID:RR-Studio,項目名稱:RealEstateCrm,代碼行數:30,代碼來源:CitySelectList.cs

示例5: Process

 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     output.PostContent
         .AppendHtml("<footer>")
         .Append((string)ViewContext.ViewData["footer"])
         .AppendHtml("</footer>");
 }
開發者ID:huoxudong125,項目名稱:Mvc,代碼行數:7,代碼來源:FooterTagHelper.cs

示例6: Process

        /// <inheritdoc />
        /// <remarks>Does nothing if <see cref="ValidationSummary"/> is <see cref="ValidationSummary.None"/>.</remarks>
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            if (ValidationSummary == ValidationSummary.None)
            {
                return;
            }

            var tagBuilder = Generator.GenerateValidationSummary(
                ViewContext,
                excludePropertyErrors: ValidationSummary == ValidationSummary.ModelOnly,
                message: null,
                headerTag: null,
                htmlAttributes: null);
            if (tagBuilder != null)
            {
                output.MergeAttributes(tagBuilder);
                output.PostContent.Append(tagBuilder.InnerHtml);
            }
        }
開發者ID:huoxudong125,項目名稱:Mvc,代碼行數:31,代碼來源:ValidationSummaryTagHelper.cs

示例7: BootstrapProcess

 protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output) {
     if (HiddenXs)
         output.AddCssClass("hidden-xs");
     if (HiddenSm)
         output.AddCssClass("hidden-sm");
     if (HiddenMd)
         output.AddCssClass("hidden-md");
     if (HiddenLg)
         output.AddCssClass("hidden-lg");
     if (HiddenPrint)
         output.AddCssClass("hidden-print");
     if (SrOnly || SrOnlyFocusable)
         output.AddCssClass("sr-only");
     if (SrOnlyFocusable)
         output.AddCssClass("sr-only-focusable");
     if (VisibleXs != null)
         output.AddCssClass("visible-xs-" + VisibleXs.Value.GetDescription());
     if (VisibleSm != null)
         output.AddCssClass("visible-sm-" + VisibleSm.Value.GetDescription());
     if (VisibleMd != null)
         output.AddCssClass("visible-md-" + VisibleMd.Value.GetDescription());
     if (VisibleLg != null)
         output.AddCssClass("visible-lg-" + VisibleLg.Value.GetDescription());
     if (VisiblePrint != null)
         output.AddCssClass("visible-print-" + VisiblePrint.Value.GetDescription());
 }
開發者ID:Pietervdw,項目名稱:BootstrapTagHelpers,代碼行數:26,代碼來源:ResponsiveUtilitiesTagHelper.cs

示例8: Process

        public override async void Process(TagHelperContext context, TagHelperOutput output)
        {
            var originalContent = await output.GetChildContentAsync();

            output.AppendClass("form-group");

            TagBuilder labelBuilder = null;
            if (!originalContent.GetContent().Contains("<label"))
            {
                labelBuilder = FormGroupLabel.Get(Horizontal, LabelText);
            }

            var contentDiv = new TagBuilder("div");

            if (Horizontal)
            {
                contentDiv.AddCssClass("col-sm-8");
            }

            contentDiv.InnerHtml.AppendHtml(originalContent.GetContent());
            
            output.TagName = "div";
            output.Content.Clear();
            if (labelBuilder != null)
            {
                output.Content.Append(labelBuilder);
            }
            output.Content.Append(contentDiv);

            base.Process(context, output);
        }
開發者ID:neutmute,項目名稱:steelcap,代碼行數:31,代碼來源:FormGroupTagHelper.cs

示例9: ProcessNonCheckControl

 private void ProcessNonCheckControl(TagHelperOutput output) {
     output.AddCssClass("form-control");
     if (!string.IsNullOrEmpty(PostAddonText) || !string.IsNullOrEmpty(PreAddonText)) {
         if ((Size ?? BootstrapTagHelpers.Size.Default) != BootstrapTagHelpers.Size.Default) {
             Size size = Size == BootstrapTagHelpers.Size.Large
                             ? BootstrapTagHelpers.Size.Large
                             : BootstrapTagHelpers.Size.Small;
             output.PreElement.PrependHtml($"<div class=\"input-group input-group-{size.GetDescription()}\">");
         }
         else
             output.PreElement.PrependHtml("<div class=\"input-group\">");
         if (!string.IsNullOrEmpty(PreAddonText))
             output.PreElement.AppendHtml(AddonTagHelper.GenerateAddon(PreAddonText));
         if (!string.IsNullOrEmpty(PostAddonText))
             output.PostElement.AppendHtml(AddonTagHelper.GenerateAddon(PostAddonText));
         output.PostElement.AppendHtml("</div>");
     }
     else if (Size != null && Size != BootstrapTagHelpers.Size.Default)
         output.AddCssClass("input-" + Size.Value.GetDescription());
     if (!string.IsNullOrEmpty(HelpText))
         if (InputGroupContext != null)
             InputGroupContext.Output.PostElement.PrependHtml(HelpBlockTagHelper.GenerateHelpBlock(HelpText));
         else
             output.PostElement.AppendHtml(HelpBlockTagHelper.GenerateHelpBlock(HelpText));
     if (InputGroupContext==null)
     if (FormGroupContext != null)
         FormGroupContext.WrapInDivForHorizontalForm(output, !string.IsNullOrEmpty(Label));
     else if (FormContext != null)
         FormContext.WrapInDivForHorizontalForm(output, !string.IsNullOrEmpty(Label));
     if (!string.IsNullOrEmpty(Label))
         if (InputGroupContext == null)
             output.PreElement.Prepend(LabelTagHelper.GenerateLabel(Label, Id, FormContext));
         else
             InputGroupContext.Output.PreElement.Prepend(LabelTagHelper.GenerateLabel(Label, Id,
                                                                                      FormContext));
     if (FormGroupContext != null && FormGroupContext.HasFeedback &&
         FormGroupContext.ValidationContext != null) {
         string cssClass;
         string srText;
         switch (FormGroupContext.ValidationContext.Value) {
             case ValidationContext.Success:
                 cssClass = "ok";
                 srText = Ressources.ValidationSuccess;
                 break;
             case ValidationContext.Warning:
                 cssClass = "warning-sign";
                 srText = Ressources.ValidationWarning;
                 break;
             case ValidationContext.Error:
                 cssClass = "remove";
                 srText = Ressources.ValidationError;
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
         output.PostElement.PrependHtml(
                                        $"<span class=\"glyphicon glyphicon-{cssClass} form-control-feedback\" aria-hidden=\"true\"></span>");
         output.PostElement.PrependHtml($"<span class=\"sr-only\">({srText})</span>");
     }
 }
開發者ID:Pietervdw,項目名稱:BootstrapTagHelpers,代碼行數:60,代碼來源:InputTagHelper.cs

示例10: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            TagBuilder table = new TagBuilder("table");
            table.GenerateId(context.UniqueId, "id");
            var attributes = context.AllAttributes.Where(a => a.Name != ItemsAttributeName).ToDictionary(a => a.Name);
            table.MergeAttributes(attributes);

            var tr = new TagBuilder("tr");
            var heading = Items.First();
            PropertyInfo[] properties = heading.GetType().GetProperties();
            foreach (var prop in properties)
            {
                var th = new TagBuilder("th");
                th.InnerHtml.Append(prop.Name);
              
                tr.InnerHtml.Append(th);
            }
            table.InnerHtml.Append(tr);
          
            foreach (var item in Items)
            {

                tr = new TagBuilder("tr");
                foreach (var prop in properties)
                {
                    var td = new TagBuilder("td");
                    td.InnerHtml.Append(prop.GetValue(item).ToString());
                    tr.InnerHtml.Append(td);
                }
                table.InnerHtml.Append(tr);
            }
            
            output.Content.Append(table.InnerHtml);
        }
開發者ID:CNinnovation,項目名稱:TechConference2016,代碼行數:34,代碼來源:TableTagHelper.cs

示例11: WrapInDivForHorizontalForm

 public void WrapInDivForHorizontalForm(TagHelperOutput output, bool hasLabel) {
     if (Horizontal) {
         var builder = new TagBuilder("div") {TagRenderMode = TagRenderMode.StartTag};
         if (LabelWidthXs != 0) {
             builder.AddCssClass("col-xs-" + (12 - LabelWidthXs));
             if (!hasLabel)
                 builder.AddCssClass("col-xs-offset-" + LabelWidthXs);
         }
         if (LabelWidthSm != 0) {
             builder.AddCssClass("col-sm-" + (12 - LabelWidthSm));
             if (!hasLabel)
                 builder.AddCssClass("col-sm-offset-" + LabelWidthSm);
         }
         if (LabelWidthMd != 0) {
             builder.AddCssClass("col-md-" + (12 - LabelWidthMd));
             if (!hasLabel)
                 builder.AddCssClass("col-md-offset-" + LabelWidthMd);
         }
         if (LabelWidthLg != 0) {
             builder.AddCssClass("col-lg-" + (12 - LabelWidthLg));
             if (!hasLabel)
                 builder.AddCssClass("col-lg-offset-" + LabelWidthLg);
         }
         output.PreElement.Prepend(builder);
         output.PostElement.AppendHtml("</div>");
     }
 }
開發者ID:Pietervdw,項目名稱:BootstrapTagHelpers,代碼行數:27,代碼來源:FormTagHelper.cs

示例12: ProcessAsync

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            (HtmlHelper as ICanHasViewContext)?.Contextualize(ViewContext);

            var content = await output.GetChildContentAsync();
            output.Content.SetContent(HtmlHelper.Hidden(Name, content.GetContent(HtmlEncoder)));
        }
開發者ID:huoxudong125,項目名稱:Mvc,代碼行數:7,代碼來源:HiddenTagHelper.cs

示例13: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "select";
            output.TagMode = TagMode.StartTagAndEndTag;

            output.AppendClass("form-control");

            var optionsList = new List<TagBuilder>();

            if (Items == null)
            {
                Items = new List<SelectListItem>();
            }

            foreach (var item in Items)
            {
                var option = new TagBuilder("option");
                option.Attributes.Add("value", item.Value);
                option.InnerHtml.Append(item.Text);

                optionsList.Add(option);
            }

            optionsList.ForEach(o =>
            {
                output.Content.Append(o);
            });

            base.Process(context, output);
        }
開發者ID:neutmute,項目名稱:steelcap,代碼行數:30,代碼來源:DropdownTagHelper.cs

示例14: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            //if no scripts were added, suppress the contents
            if (!_httpContextAccessor.HttpContext.Items.ContainsKey(InlineScriptConcatenatorTagHelper.ViewDataKey))
            {
                output.SuppressOutput();
                return;
            }

            //Otherwise get all the scripts for the page
            var scripts =
                _httpContextAccessor.HttpContext.Items[InlineScriptConcatenatorTagHelper.ViewDataKey] as
                    IDictionary<string, NamedScriptInfo>;
            if (null == scripts)
            {
                output.SuppressOutput();
                return;
            }

            //Concatenate all of them and set them as the contents of this tag
            var allScripts = string.Join("\r\n", OrderedScripts(scripts.Values).Select(os => os.Script));
            output.TagMode = TagMode.StartTagAndEndTag;
            //HACK:Need to figure out how to get rid of the script tags for the placeholder element
            allScripts = $"</script><!--Rendered Scripts Output START-->\r\n{allScripts}\r\n</script><!--Rendered Scripts Output END--><script>";//HACK:ugly
            var unminifiedContent = output.Content.SetHtmlContent(allScripts);
            Debug.WriteLine(unminifiedContent.GetContent());
            //TODO:Impliment dynamic minification (Assuming that some scenarios will be sped up, and others slowed down.  Leave choice to user)
        }
開發者ID:SvdSinner,項目名稱:ScriptManagerPlus,代碼行數:28,代碼來源:InlineScriptTagHelper.cs

示例15: ProcessAsync

 public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
 {
     var childContent = await output.GetChildContentAsync();
     var modalContext = (ModalContext)context.Items[typeof(ModalTagHelper)];
     modalContext.Body = childContent;
     output.SuppressOutput();
 }
開發者ID:candoumbe,項目名稱:TagHelperSamples,代碼行數:7,代碼來源:ModalBodyTagHelper.cs


注:本文中的Microsoft.AspNet.Razor.TagHelpers.TagHelperOutput類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。