當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。