• <small id='qBpKM'></small><noframes id='qBpKM'>

  • <i id='qBpKM'><tr id='qBpKM'><dt id='qBpKM'><q id='qBpKM'><span id='qBpKM'><b id='qBpKM'><form id='qBpKM'><ins id='qBpKM'></ins><ul id='qBpKM'></ul><sub id='qBpKM'></sub></form><legend id='qBpKM'></legend><bdo id='qBpKM'><pre id='qBpKM'><center id='qBpKM'></center></pre></bdo></b><th id='qBpKM'></th></span></q></dt></tr></i><div id='qBpKM'><tfoot id='qBpKM'></tfoot><dl id='qBpKM'><fieldset id='qBpKM'></fieldset></dl></div>

  • <tfoot id='qBpKM'></tfoot>

      • <bdo id='qBpKM'></bdo><ul id='qBpKM'></ul>

        <legend id='qBpKM'><style id='qBpKM'><dir id='qBpKM'><q id='qBpKM'></q></dir></style></legend>

        我可以在返回 html 的自定义 Tag Helper 中使用 Tag Helper 吗?

        时间:2023-07-11

      1. <legend id='hu2cG'><style id='hu2cG'><dir id='hu2cG'><q id='hu2cG'></q></dir></style></legend>
          <bdo id='hu2cG'></bdo><ul id='hu2cG'></ul>

        • <i id='hu2cG'><tr id='hu2cG'><dt id='hu2cG'><q id='hu2cG'><span id='hu2cG'><b id='hu2cG'><form id='hu2cG'><ins id='hu2cG'></ins><ul id='hu2cG'></ul><sub id='hu2cG'></sub></form><legend id='hu2cG'></legend><bdo id='hu2cG'><pre id='hu2cG'><center id='hu2cG'></center></pre></bdo></b><th id='hu2cG'></th></span></q></dt></tr></i><div id='hu2cG'><tfoot id='hu2cG'></tfoot><dl id='hu2cG'><fieldset id='hu2cG'></fieldset></dl></div>
            <tfoot id='hu2cG'></tfoot>

                1. <small id='hu2cG'></small><noframes id='hu2cG'>

                    <tbody id='hu2cG'></tbody>
                  本文介绍了我可以在返回 html 的自定义 Tag Helper 中使用 Tag Helper 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我最近遇到了一种情况,我想在标签助手中使用标签助手.我环顾四周,找不到其他人尝试这样做,是我使用了糟糕的约定还是缺少文档?

                  I recently ran into a situation where I would like to use a tag helper within a tag helper. I looked around and couldn't find anyone else trying to do this, am I using a poor convention or am I missing documentation?

                  例如.标签助手 A 输出包含另一个标签助手的 HTML.

                  Ex. Tag Helper A outputs HTML that contains another tag helper.

                  例如.

                  [HtmlTargetElement("tag-name")]
                  public class RazorTagHelper : TagHelper
                  {
                      public override void Process(TagHelperContext context, TagHelperOutput output)
                      {
                          StringBuilder sb = new StringBuilder();
                          sb.Append("<a asp-action="Home" ");
                          output.Content.SetHtmlContent(sb.ToString());
                      }
                  }
                  

                  有没有办法让我处理 <a asp-action></a> 来自 C# 的标签助手?还是用标签助手重新处理输出的 HTML?

                  Is there a way for me to process the <a asp-action> </a> tag helper from C#? Or to reprocess the output HTML with tag helpers?

                  推荐答案

                  不,你不能.TagHelpers 是 Razor 解析时间功能.

                  No you cannot. TagHelpers are a Razor parse time feature.

                  另一种方法是创建 TagHelper 并手动调用其 ProcessAsync/Process 方法.又名:

                  One alternative is creating a TagHelper and manually invoking its ProcessAsync/Process method. Aka:

                  var anchorTagHelper = new AnchorTagHelper
                  {
                      Action = "Home",
                  };
                  var anchorOutput = new TagHelperOutput("a", new TagHelperAttributeList(), (useCachedResult, encoder) => new HtmlString());
                  var anchorContext = new TagHelperContext(
                      new TagHelperAttributeList(new[] { new TagHelperAttribute("asp-action", new HtmlString("Home")) }),
                      new Dictionary<object, object>(),
                      Guid.NewGuid());
                  await anchorTagHelper.ProcessAsync(anchorContext, anchorOutput);
                  output.Content.SetHtmlContent(anchorOutput);
                  

                  这篇关于我可以在返回 html 的自定义 Tag Helper 中使用 Tag Helper 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何将 ASP.NET Core UserSecrets 部署到生产环境 下一篇:ASP.Net MVC 5 中的 Cookie

                  相关文章

                    <legend id='kGhz0'><style id='kGhz0'><dir id='kGhz0'><q id='kGhz0'></q></dir></style></legend>
                    <i id='kGhz0'><tr id='kGhz0'><dt id='kGhz0'><q id='kGhz0'><span id='kGhz0'><b id='kGhz0'><form id='kGhz0'><ins id='kGhz0'></ins><ul id='kGhz0'></ul><sub id='kGhz0'></sub></form><legend id='kGhz0'></legend><bdo id='kGhz0'><pre id='kGhz0'><center id='kGhz0'></center></pre></bdo></b><th id='kGhz0'></th></span></q></dt></tr></i><div id='kGhz0'><tfoot id='kGhz0'></tfoot><dl id='kGhz0'><fieldset id='kGhz0'></fieldset></dl></div>
                      <bdo id='kGhz0'></bdo><ul id='kGhz0'></ul>
                    <tfoot id='kGhz0'></tfoot>

                    1. <small id='kGhz0'></small><noframes id='kGhz0'>