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


C# TagHelpers.TagHelperContext类代码示例

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


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

示例1: Process_DoesNothingIfTagNameIsNull

        public void Process_DoesNothingIfTagNameIsNull()
        {
            // Arrange
            var tagHelperOutput = new TagHelperOutput(
                tagName: null,
                attributes: new TagHelperAttributeList
                {
                    { "href", "~/home/index.html" }
                },
                getChildContentAsync: (useCachedResult, encoder) => Task.FromResult<TagHelperContent>(null));

            var tagHelper = new UrlResolutionTagHelper(Mock.Of<IUrlHelperFactory>(), new HtmlTestEncoder());
            var context = new TagHelperContext(
                allAttributes: new TagHelperAttributeList(
                    Enumerable.Empty<TagHelperAttribute>()),
                items: new Dictionary<object, object>(),
                uniqueId: "test");

            // Act
            tagHelper.Process(context, tagHelperOutput);

            // Assert
            var attribute = Assert.Single(tagHelperOutput.Attributes);
            Assert.Equal("href", attribute.Name, StringComparer.Ordinal);
            var attributeValue = Assert.IsType<string>(attribute.Value);
            Assert.Equal("~/home/index.html", attributeValue, StringComparer.Ordinal);
        }
开发者ID:cemalshukriev,项目名称:Mvc,代码行数:27,代码来源:UrlResolutionTagHelperTest.cs

示例2: ProcessAsync

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var request = ViewContext.HttpContext.Request;
            var result = await Prerenderer.RenderToString(
                _applicationBasePath,
                _nodeServices,
                new JavaScriptModuleExport(ModuleName)
                {
                    ExportName = ExportName,
                    WebpackConfig = WebpackConfigPath
                },
                request.GetEncodedUrl(),
                request.Path + request.QueryString.Value,
                CustomDataParameter);
            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}</script>");
                }
            }
        }
开发者ID:Christiestporter,项目名称:JavaScriptServices,代码行数:33,代码来源:PrerenderTagHelper.cs

示例3: 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)
            {
                // Perf: Avoid allocating enumerator
                for (var i = 0; i < formContext.EndOfFormContent.Count; i++)
                {
                    output.PostContent.AppendHtml(formContext.EndOfFormContent[i]);
                }
            }

            // Reset the FormContext
            ViewContext.FormContext = new FormContext();
        }
开发者ID:cemalshukriev,项目名称:Mvc,代码行数:28,代码来源:RenderAtEndOfFormTagHelper.cs

示例4: CreateContext

 public TagHelperContext CreateContext(bool hasMarkdownAttribute)
 {
     if (hasMarkdownAttribute)
         _inputAttributes.Add(new TagHelperAttribute("markdown", ""));
     var context = new TagHelperContext(_inputAttributes, _items, Guid.NewGuid().ToString());
     return context;
 }
开发者ID:ciker,项目名称:TagHelperSamples,代码行数:7,代码来源:MarkdownHelperToTheTagHelpers.cs

示例5: TagHelperExecutionContext

        /// <summary>
        /// Instantiates a new <see cref="TagHelperExecutionContext"/>.
        /// </summary>
        /// <param name="tagName">The HTML tag name in the Razor source.</param>
        /// <param name="tagMode">HTML syntax of the element in the Razor source.</param>
        /// <param name="items">The collection of items used to communicate with other
        /// <see cref="ITagHelper"/>s</param>
        /// <param name="uniqueId">An identifier unique to the HTML element this context is for.</param>
        /// <param name="executeChildContentAsync">A delegate used to execute the child content asynchronously.</param>
        /// <param name="startTagHelperWritingScope">
        /// A delegate used to start a writing scope in a Razor page and optionally override the page's
        /// <see cref="HtmlEncoder"/> within that scope.
        /// </param>
        /// <param name="endTagHelperWritingScope">A delegate used to end a writing scope in a Razor page.</param>
        public TagHelperExecutionContext(
            string tagName,
            TagMode tagMode,
            IDictionary<object, object> items,
            string uniqueId,
            Func<Task> executeChildContentAsync,
            Action<HtmlEncoder> startTagHelperWritingScope,
            Func<TagHelperContent> endTagHelperWritingScope)
        {
            if (startTagHelperWritingScope == null)
            {
                throw new ArgumentNullException(nameof(startTagHelperWritingScope));
            }

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

            _tagHelpers = new List<ITagHelper>();
            _allAttributes = new TagHelperAttributeList();

            Context = new TagHelperContext(_allAttributes, items, uniqueId);
            Output = new TagHelperOutput(tagName, new TagHelperAttributeList(), GetChildContentAsync)
            {
                TagMode = tagMode
            };

            Reinitialize(tagName, tagMode, items, uniqueId, executeChildContentAsync);

            _startTagHelperWritingScope = startTagHelperWritingScope;
            _endTagHelperWritingScope = endTagHelperWritingScope;
        }
开发者ID:x-strong,项目名称:Razor,代码行数:47,代码来源:TagHelperExecutionContext.cs

示例6: DefaultServerAutocompleteProcessor

 public DefaultServerAutocompleteProcessor(TagHelperContext context, TagHelperOutput output, AutocompleteTagHelper tag, AutocompleteOptions options)
 {
     this.context = context;
     this.output = output;
     this.tag = tag;
     this.options = options;
 }
开发者ID:MvcControlsToolkit,项目名称:MvcControlsToolkit.ControlsCore,代码行数:7,代码来源:DefaultServerAutocompleteProcessor.cs

示例7: 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.SetAttribute("style", style + prettyStyle);
            }
        }
开发者ID:cemalshukriev,项目名称:Mvc,代码行数:26,代码来源:PrettyTagHelper.cs

示例8: Process

        /// <inheritdoc />
        /// <remarks>Does nothing if <see cref="For"/> is <c>null</c>.</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));
            }

            var tagBuilder = Generator.GenerateTextArea(
                ViewContext,
                For.ModelExplorer,
                For.Name,
                rows: 0,
                columns: 0,
                htmlAttributes: null);

            if (tagBuilder != null)
            {
                // Overwrite current Content to ensure expression result round-trips correctly.
                output.Content.SetHtmlContent(tagBuilder.InnerHtml);

                output.MergeAttributes(tagBuilder);
            }
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:30,代码来源:TextAreaTagHelper.cs

示例9: ProcessAsync

 public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
 {
     if (DisplayProperty == null && (DisplayPropertyExplorer == null || DisplayPropertyExpressionOverride==null))
         new ArgumentNullException("display-property/display-expression-override+display-explorer");
     if (For == null && (ForPropertyExplorer == null || ForExpressionOverride == null))
         new ArgumentNullException("asp-for/for-expression-override+for-explorer");
     if (string.IsNullOrWhiteSpace(ItemsDisplayProperty)) new ArgumentNullException("items-display-property");
     if (string.IsNullOrWhiteSpace(ItemsValueProperty)) new ArgumentNullException("items-value-property");
     if (string.IsNullOrWhiteSpace(ItemsUrl)) new ArgumentNullException("items-url");
     if (string.IsNullOrWhiteSpace(UrlToken)) new ArgumentNullException("url-token");
     if (string.IsNullOrWhiteSpace(DataSetName)) new ArgumentNullException("dataset-name");
     if (MaxResults == 0) MaxResults=20;
     if (MinChars == 0) MinChars = 3;
     var currProvider = ViewContext.TagHelperProvider();
     var resolver = jsonOptions.SerializerSettings.ContractResolver as DefaultContractResolver;
     var vd = ViewContext.ViewData;
     var options = new AutocompleteOptions
     {
         Generator = generator,
         PropertyResolver = resolver != null ? resolver.GetResolvedPropertyName : new Func<string, string>(x => x),
         ForcedValueName =  currProvider.GenerateNames ? vd.GetFullHtmlFieldName(ForExpressionOverride ?? For.Name) : null,
         ForcedDisplayName = currProvider.GenerateNames ? vd.GetFullHtmlFieldName(DisplayPropertyExpressionOverride ?? DisplayProperty.Name) : null,
         NoId= !currProvider.GenerateNames || ViewContext.IsFilterRendering()
     };
     await currProvider.GetTagProcessor(TagName)(context, output, this, options, null);
 }
开发者ID:MvcControlsToolkit,项目名称:MvcControlsToolkit.ControlsCore,代码行数:26,代码来源:AutocompleteTagHelper.cs

示例10: DefaultServerGridProcessor

 public DefaultServerGridProcessor(TagHelperContext context, TagHelperOutput output, GridTagHelper tag, GridOptions options, ContextualizedHelpers helpers)
 {
     this.context = context; this.output = output; this.tag = tag;
     this.options = options; this.helpers = helpers;
     basePrefix = tag.For.Name;
     AdjustColumns();
 }
开发者ID:MvcControlsToolkit,项目名称:MvcControlsToolkit.ControlsCore,代码行数:7,代码来源:DefaultServerGridProcessor.cs

示例11: Process

        public override async void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "div";

            output.AppendClass("widget-box");
            output.AppendClass(Class);
            
            var originalContent = await output.GetChildContentAsync();
            var innerHtml = originalContent.GetContent();

            output.Content.Clear();

            if (!innerHtml.Contains(WidgetBoxHeaderHelper.HeaderCss))
            {
                // user is taking easy/lazy way of declaring the widget box
                output.Content.AppendHtml(WidgetBoxHeaderHelper.GetFullHeader(Title, IsCollapsible));
                var widgetBodyDiv = WidgetBoxBodyHelper.GetFullBodyInternals(Padding, innerHtml);
                output.Content.AppendHtml(widgetBodyDiv);
            }
            else
            {
                // user is doing the hardwork themselves
                output.Content.AppendHtml(innerHtml);
            }
            
            base.Process(context, output);
        }
开发者ID:CormacdeBarra,项目名称:steelcap,代码行数:27,代码来源:WidgetBoxHelper.cs

示例12: Process

 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     if (ShowIfNull != null)
     {
         output.SuppressOutput();
     }
 }
开发者ID:wondertrap,项目名称:AspNet5IdentityServerAngularImplicitFlow,代码行数:7,代码来源:HideShowTagHelpers.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.AppendHtml(o);
            });

            base.Process(context, output);
        }
开发者ID:CormacdeBarra,项目名称:steelcap,代码行数:30,代码来源:DropdownTagHelper.cs

示例14: Reinitialize_AllowsContextToBeReused

        public void Reinitialize_AllowsContextToBeReused()
        {
            // Arrange
            var initialUniqueId = "123";
            var expectedUniqueId = "456";
            var initialItems = new Dictionary<object, object>
            {
                { "test-entry", 1234 }
            };
            var expectedItems = new Dictionary<object, object>
            {
                { "something", "new" }
            };
            var initialAttributes = new TagHelperAttributeList
            {
                { "name", "value" }
            };
            var context = new TagHelperContext(initialAttributes, initialItems, initialUniqueId);

            // Act
            context.Reinitialize(expectedItems, expectedUniqueId);

            // Assert
            Assert.Same(expectedItems, context.Items);
            Assert.Equal(expectedUniqueId, context.UniqueId);
            Assert.Empty(context.AllAttributes);
        }
开发者ID:,项目名称:,代码行数:27,代码来源:

示例15: Process

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            //load the content items in the specified section
            if (!string.IsNullOrWhiteSpace(Section))
            {
                //Set Content edit properties on tags when logged in
                if (_webSite?.IsAuthenticated(ViewContext.HttpContext.User) == true)
                {
                    output.Attributes.Add("data-miniwebsection", Section);
                }

                //contextualize the HtmlHelper for the current ViewContext
                (_htmlHelper as IViewContextAware)?.Contextualize(ViewContext);
                //get out the current ViewPage for the Model.
                var view = ViewContext.View as RazorView;
                var viewPage = view?.RazorPage as RazorPage<ISitePage>;
                output.Content.Clear();

                if (viewPage != null)
                {
                    var sectionContent = SectionContent(_htmlHelper, viewPage.Model, Section);
                    output.Content.AppendHtml(sectionContent);
                }
            }
        }
开发者ID:IRooc,项目名称:miniweb-coreclr,代码行数:25,代码来源:MiniWebSectionTagHelper.cs


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