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


C# TagHelpers.TagHelperContext类代码示例

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


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

示例1: GetContent

        private async Task<string> GetContent(TagHelperContext context)
        {
            if (Content == null)
                return (await context.GetChildContentAsync()).GetContent();

            return Content.Model?.ToString();
        }
开发者ID:freemsly,项目名称:TagHelperSamples,代码行数:7,代码来源:MarkdownTagHelper.cs

示例2: Process

 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     if (!Condition)
     {
         output.SuppressOutput();
     }
 }
开发者ID:ChujianA,项目名称:aspnetcore-doc-cn,代码行数:7,代码来源:ConditionTagHelper.cs

示例3: ProcessAsync

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (!string.IsNullOrWhiteSpace(ModelName) && ModelData != null)
            {
                modelContext.Initialize(ModelData);

                var script = new TagBuilder("script");
                script.Attributes.Add("model", ModelName);
                script.Attributes.Add("type", "application/json");
                if (ModelPersistent)
                {
                    script.Attributes.Add("persistent", "");
                }
                script.InnerHtml = new StringHtmlContent(jsonHelper.Serialize(ModelData).ToString());

                output.Attributes.Add("model", ModelName);
                using (var writer = new StringWriter())
                {
                    script.WriteTo(writer, new HtmlEncoder());
                    output.PreContent.SetContent(writer.ToString());
                }
            }
            else if (!string.IsNullOrWhiteSpace(Scope))
            {
                output.Attributes.Add("scope", Scope);
                modelContext.Scope(Scope);
            }

            output.Attributes.Add("name", Name);

            await base.ProcessAsync(context, output);
        }
开发者ID:tuespetre,项目名称:html-mvc-aspnet5,代码行数:32,代码来源:ViewTagHelper.cs

示例4: ProcessAsync

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

            var content = await context.GetChildContentAsync();
            output.Content.SetContent(HtmlHelper.Hidden(Name, content.GetContent(HtmlEncoder)));
        }
开发者ID:4myBenefits,项目名称:Mvc,代码行数:7,代码来源:HiddenTagHelper.cs

示例5: ProcessAsync

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var childContent = await context.GetChildContentAsync();
            var content = childContent.GetContent();
            var template =
[email protected]"<div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <button type = 'button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
        <h4 class='modal-title' id='{context.UniqueId}Label'>{Title}</h4>
      </div>
        {content}
    </div>
  </div>";
            output.TagName = "div";
            output.Attributes["role"] = "dialog";
            output.Attributes["id"] = Id;
            output.Attributes["aria-labelledby"] = $"{context.UniqueId}Label";
            output.Attributes["tabindex"] = "-1";
            var classNames = "modal fade";
            if (output.Attributes.ContainsName("class"))
            {
                classNames = string.Format("{0} {1}", output.Attributes["class"].Value, classNames);
            }
            output.Attributes["class"] = classNames;

            output.Content.SetContent(template);
        }
开发者ID:arashkeivan,项目名称:TagHelperSamples,代码行数:28,代码来源:ModalTagHelper.cs

示例6: Process

 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     output.TagName = null;
     output.Content.AppendEncoded("<b>");
     output.Content.Append(text);
     output.Content.AppendEncoded("</b>");
 }
开发者ID:kichalla,项目名称:TagHelpersVerification,代码行数:7,代码来源:GreetingsTagHelper.cs

示例7: ProcessAsync

        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            var contacts = new ContactRepository();
            var contact = await contacts.GetAsync(Email);

            if (contact == null)
            {
                output.TagName = null;
                return;
            }

            output.TagName = "div";
            output.PreContent.SetContentEncoded("<form>");

            var hidden = CreateInputElement("hidden", contact.Id.ToString());
            var textBox = CreateInputElement("text", "");
            var submit = CreateInputElement("submit", "Send Message");

            output.Content.Append(hidden);
            output.Content.Append(textBox);
            output.Content.Append(submit);

            output.PostContent.SetContentEncoded("</form>");


        }
开发者ID:jwmcpeak,项目名称:Create-Tag-Helpers-in-ASP.NET-5,代码行数:26,代码来源:ContactTagHelper.cs

示例8: Process

        //[HtmlAttributeName("DisplaySteps")]
        //public bool DisplaySteps { get; set; }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            // [initial-board] -> [solved-board]
            // seqences of boards

            if(MoveResult == null) {
                output.SuppressOutput();
                return;
            }
            output.TagName = "span";
            AddBoardToOutput(MoveResult.OriginalBoard.Board, output);

            output.Content.AppendEncoded(Environment.NewLine);
            output.Content.AppendEncoded(@"&nbsp;");

            AddBoardToOutput(MoveResult.CurrentBoard.Board, output);

            //if (DisplaySteps) {
            //    output.Content.AppendEncoded(Environment.NewLine);
            //    output.Content.AppendEncoded(@"<br/>");
            //    output.Content.AppendEncoded(@"<div style=""height: 10px;"">&nbsp;</div>");

            //    foreach (var move in MoveResult.MovesPlayed) {
            //        AddBoardToOutput(move.Board, output);
            //        output.Content.AppendEncoded(@"&nbsp;");
            //        output.Content.AppendEncoded(Environment.NewLine);
            //    }
            //}
        }
开发者ID:sayedihashimi,项目名称:sudoku,代码行数:31,代码来源:MoveResultTagHelper.cs

示例9: CopyHtmlAttribute_DoesNotOverrideAttributes

        public void CopyHtmlAttribute_DoesNotOverrideAttributes()
        {
            // Arrange
            var attributeName = "hello";
            var tagHelperOutput = new TagHelperOutput(
                "p",
                attributes: new Dictionary<string, object>()
                {
                    { attributeName, "world2" }
                });
            var expectedAttribute = new KeyValuePair<string, object>(attributeName, "world2");
            var tagHelperContext = new TagHelperContext(
                allAttributes: new Dictionary<string, object>(StringComparer.Ordinal)
                {
                    { attributeName, "world" }
                },
                items: new Dictionary<object, object>(),
                uniqueId: "test",
                getChildContentAsync: () =>
                {
                    var tagHelperContent = new DefaultTagHelperContent();
                    tagHelperContent.Append("Something Else");
                    return Task.FromResult<TagHelperContent>(tagHelperContent);
                });

            // Act
            tagHelperOutput.CopyHtmlAttribute(attributeName, tagHelperContext);

            // Assert
            var attribute = Assert.Single(tagHelperOutput.Attributes);
            Assert.Equal(expectedAttribute, attribute);
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:32,代码来源:TagHelperOutputExtensionsTest.cs

示例10: ProcessAsync

 public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
 {
     var childContent = await context.GetChildContentAsync();
     var modalContext = (ModalContext)context.Items[typeof(ModalTagHelper)];
     modalContext.Body = childContent;
     output.SuppressOutput();
 }
开发者ID:freemsly,项目名称:TagHelperSamples,代码行数:7,代码来源:ModalBodyTagHelper.cs

示例11: Process

 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     if (!string.IsNullOrWhiteSpace(Value))
     {
         output.Content.SetContent(Value);
     }
 }
开发者ID:christiansparre,项目名称:aspnettaghelperissue,代码行数:7,代码来源:DivValueTagHelper.cs

示例12: Process

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

            ConditionalCommentType type = CommentType;

            string ifCommentStartPart;
            string ifCommentEndPart;

            switch (type)
            {
                case ConditionalCommentType.Hidden:
                    ifCommentStartPart = "<!--[if ";
                    ifCommentEndPart = "]>";

                    break;
                case ConditionalCommentType.RevealedValidating:
                    ifCommentStartPart = "<!--[if ";
                    ifCommentEndPart = "]><!-->";

                    break;
                case ConditionalCommentType.RevealedValidatingSimplified:
                    ifCommentStartPart = "<!--[if ";
                    ifCommentEndPart = "]>-->";

                    break;
                case ConditionalCommentType.Revealed:
                    ifCommentStartPart = "<![if ";
                    ifCommentEndPart = "]>";

                    break;
                default:
                    throw new NotSupportedException();
            }

            TagHelperContent preContent = output.PreContent;
            preContent.Append(ifCommentStartPart);
            preContent.Append(Expression);
            preContent.Append(ifCommentEndPart);

            string endIfComment;

            switch (type)
            {
                case ConditionalCommentType.Hidden:
                    endIfComment = "<![endif]-->";
                    break;
                case ConditionalCommentType.RevealedValidating:
                case ConditionalCommentType.RevealedValidatingSimplified:
                    endIfComment = "<!--<![endif]-->";
                    break;
                case ConditionalCommentType.Revealed:
                    endIfComment = "<![endif]>";
                    break;
                default:
                    throw new NotSupportedException();
            }

            output.PostContent.Append(endIfComment);
        }
开发者ID:jinzesudawei,项目名称:WebMarkupMin,代码行数:60,代码来源:ConditionalCommentTagHelper.cs

示例13: Process

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

            var actionNames = ControllerType.GetTypeInfo().DeclaredMethods
                .Where(methodInfo => methodInfo.IsPublic)
                .Select(methodInfo => methodInfo.Name);

            var controllerName = ControllerType.Name;

            if (controllerName.EndsWith("Controller", StringComparison.OrdinalIgnoreCase))
            {
                controllerName = controllerName.Substring(0, controllerName.Length - "Controller".Length);
            }

            foreach (var action in actionNames)
            {
                if (!string.Equals(action, Exclude, StringComparison.OrdinalIgnoreCase))
                {
                    var displayName = action;

                    if (string.Equals(action, "Index", StringComparison.OrdinalIgnoreCase))
                    {
                        displayName = controllerName;
                    }

                    var liElement = new HtmlString($"<li><a href='{_urlHelper.Action(action, controllerName)}'>{displayName}</a></li>");
                    output.Content.Append(liElement);
                }
            }
        }
开发者ID:NTaylorMullen,项目名称:SeattleCodeCamp_9_12_2015,代码行数:32,代码来源:ControllerNavigationTagHelper.cs

示例14: Process

 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     if (Type != null && Status != null)
         throw new ArgumentException($"'{nameof(Type)}' and '{nameof(Status)}' attributes cannot be used together.");
     output.TagName = null;
     output.Content.SetContent(ShieldGenerator.GenerateShieldMarkup(Subject, Type, Status, Color, Style, Image));
 }
开发者ID:freemsly,项目名称:Acme.Helpers,代码行数:7,代码来源:ShieldTagHelper.cs

示例15: Process

 public override void Process(TagHelperContext context, TagHelperOutput output)
 {
     output.PostContent
         .AppendEncoded("<footer>")
         .Append((string)ViewContext.ViewData["footer"])
         .AppendEncoded("</footer>");
 }
开发者ID:4myBenefits,项目名称:Mvc,代码行数:7,代码来源:FooterTagHelper.cs


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