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


C# TagHelpers.TagHelperContext类代码示例

本文整理汇总了C#中Microsoft.AspNet.Razor.TagHelpers.TagHelperContext的典型用法代码示例。如果您正苦于以下问题:C# TagHelperContext类的具体用法?C# TagHelperContext怎么用?C# TagHelperContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TagHelperContext类属于Microsoft.AspNet.Razor.TagHelpers命名空间,在下文中一共展示了TagHelperContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (MakePretty.HasValue && !MakePretty.Value)
            {
                return;
            }

            if (output.TagName == null)
            {
                // Another tag helper e.g. TagHelperviewComponentTagHelper has suppressed the start and end tags.
                return;
            }

            string prettyStyle;

            if (PrettyTagStyles.TryGetValue(output.TagName, out prettyStyle))
            {
                var style = Style ?? string.Empty;
                if (!string.IsNullOrEmpty(style))
                {
                    style += ";";
                }

                output.Attributes["style"] = style + prettyStyle;
            }
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:26,代码来源:PrettyTagHelper.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)
        {
            var surroundingTagName = Surround.ToLowerInvariant();

            output.PreElement.AppendHtml($"<{surroundingTagName}>");
            output.PostElement.AppendHtml($"</{surroundingTagName}>");
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:7,代码来源:SurroundTagHelper.cs

示例5: Process

 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     if (ShowIfNull != null)
     {
         output.SuppressOutput();
     }
 }
开发者ID:pugillum,项目名称:AspNet5IdentityServerAngularImplicitFlow,代码行数:7,代码来源:HideShowTagHelpers.cs

示例6: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "div";
            if (output.Attributes["class"].IsNull())
            {
                output.Attributes["class"] = "item";
            }
            else
            {
                output.Attributes["class"].Value += " item";
            }
            /*
            <div class="item">
                        <i class="marker icon"></i>
                        <div class="content">@Html.DisplayFor(x => item.FullAddress)</div>
                    </div>
            */

            var html = new StringBuilder();

            
            html.Append($"<i class='{Icon} icon'></i>");
            html.Append($"<div class='content'>{Content}</div>");

            var childContent = output.GetChildContentAsync();
            output.Content.SetHtmlContent(html.ToString());
        }
开发者ID:RR-Studio,项目名称:RealEstateCrm,代码行数:27,代码来源:UiListItem.cs

示例7: ProcessAsync

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var request = this.contextAccessor.HttpContext.Request;
            var result = await Prerenderer.RenderToString(
                applicationBasePath: this.applicationBasePath,
                nodeServices: this.nodeServices,
                bootModule: new JavaScriptModuleExport(this.ModuleName) {
                    exportName = this.ExportName,
                    webpackConfig = this.WebpackConfigPath
                },
                requestAbsoluteUrl: UriHelper.GetEncodedUrl(this.contextAccessor.HttpContext.Request),
                requestPathAndQuery: request.Path + request.QueryString.Value);
            output.Content.SetHtmlContent(result.Html);

            // Also attach any specified globals to the 'window' object. This is useful for transferring
            // general state between server and client.
            if (result.Globals != null) {
                var stringBuilder = new StringBuilder();
                foreach (var property in result.Globals.Properties()) {
                    stringBuilder.AppendFormat("window.{0} = {1};",
                        property.Name,
                        property.Value.ToString(Formatting.None));
                }
                if (stringBuilder.Length > 0) {
                    output.PostElement.SetHtmlContent($"<script>{ stringBuilder.ToString() }</script>");
                }
            }
        }
开发者ID:jimitndiaye,项目名称:NodeServices,代码行数:28,代码来源:PrerenderTagHelper.cs

示例8: ProcessAsync

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var localizer = Localizer ?? GetViewLocalizer();

            var aspLocAttr = output.Attributes["asp-loc"];
            
            if (aspLocAttr != null)
            {
                var resourceKey = aspLocAttr.Minimized
                    ? (await output.GetChildContentAsync()).GetContent()
                    : aspLocAttr.Value.ToString();
                output.Content.SetContent(localizer.GetHtml(resourceKey));
                output.Attributes.Remove(aspLocAttr);
            }

            var localizeAttributes = output.Attributes.Where(attr => attr.Name.StartsWith("asp-loc-", StringComparison.OrdinalIgnoreCase)).ToList();

            foreach (var attribute in localizeAttributes)
            {
                var attributeToLocalize = output.Attributes[attribute.Name.Substring("asp-loc-".Length)];
                if (attributeToLocalize != null)
                {
                    var resourceKey = attribute.Minimized
                        ? attributeToLocalize.Value.ToString()
                        : attribute.Value.ToString();
                    attributeToLocalize.Value = localizer.GetHtml(resourceKey);
                }
                output.Attributes.Remove(attribute);
            }
        }
开发者ID:leloulight,项目名称:Entropy,代码行数:30,代码来源:LocalizationTagHelper.cs

示例9: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var specified = context?.AllAttributes[ImagesAttributeName]?.Name == ImagesAttributeName &&
                            Images != null && Images.Any();
            if (specified)
            {
                string classValue;
                classValue = output.Attributes.ContainsName("class")
                    ? string.Format("{0} {1}", output.Attributes["class"], "lazyload")
                    : "lazyload";
                output.Attributes["class"] = classValue;

                var images = Images.ToList();
                if (images.Count == 1)
                {
                    output.Attributes.Add("data-src", images[0]?.Url);
                }
                else
                {
                    output.Attributes.Add("data-sizes", "auto");

                    List<string> sizes = new List<string>();

                    foreach (var image in images)
                    {
                        sizes.Add(MakePath(image.Url, image.Width));
                    }
                    output.Attributes.Add("data-srcset", string.Join(",", sizes));
                }
            }
            else
            {
                base.Process(context, output);
            }
        }
开发者ID:scanham,项目名称:FlatplanRenderer,代码行数:35,代码来源:LazySizesTagHelper.cs

示例10: 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

示例11: ProcessAsync

        /// <inheritdoc />
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

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

            await output.GetChildContentAsync();

            var formContext = ViewContext.FormContext;
            if (formContext.HasEndOfFormContent)
            {
                foreach (var content in formContext.EndOfFormContent)
                {
                    output.PostContent.Append(content);
                }
            }

            // Reset the FormContext
            ViewContext.FormContext = null;
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:27,代码来源:RenderAtEndOfFormTagHelper.cs

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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