Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将innerHtml输入到输入中(使用TagHelper生成)?_C#_Anchor_Asp.net Core Mvc_Tag Helpers - Fatal编程技术网

C# 如何将innerHtml输入到输入中(使用TagHelper生成)?

C# 如何将innerHtml输入到输入中(使用TagHelper生成)?,c#,anchor,asp.net-core-mvc,tag-helpers,C#,Anchor,Asp.net Core Mvc,Tag Helpers,我使用MVC6TagHelper创建了自己的锚定标记。 如果我从属性中提供innerHtml,那么效果很好,但是我想直接从HTML中提供innerHtml。 这是我的TagHelper代码,用于自定义锚定 public string Text { get; set; } public override void Process(TagHelperContext context, TagHelperOutput output) { var builder =

我使用MVC6TagHelper创建了自己的锚定标记。 如果我从属性中提供innerHtml,那么效果很好,但是我想直接从HTML中提供innerHtml。 这是我的TagHelper代码,用于自定义锚定

   public string Text { get; set; }  

   public override void Process(TagHelperContext context, TagHelperOutput output)
   {
       var builder = new TagBuilder("a");

       output.Attributes.Add("data-controller", Controller);
       output.Attributes.Add("data-action", Action);

       if (!string.IsNullOrEmpty(Text))
       {
           builder.InnerHtml.Append(Text); // INNER HTML IS HERE!!! 
       }
       builder.AddCssClass("btn btn-link");
       output.Content.SetContent(builder);
       base.Process(context, output);
   }
现在的用法是这样的(当前情况-它可以工作)


是否可以像下面这样手动提供内部html文本?(需要的情况-目前不工作)

©2016穆拉特

为了实现这一点,我们必须使用Asyn版本的过程方法

    public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
    {
        var content = output.GetChildContentAsync().Result.GetContent();

        var builder = new TagBuilder("a");
        builder.Attributes.Add("role", "button");
        builder.Attributes.Add("id", Name);
        builder.Attributes.Add("name", Name);
        output.Attributes.Add("data-controller", Controller);
        output.Attributes.Add("data-action", Action);

        builder.InnerHtml.Append(content);

        output.Content.SetContent(builder);

        return base.ProcessAsync(context, output);
    }
通过使用ProcessAsync方法,现在我可以在打开-关闭标记之间直接给出内部html

<anchor-box name="ALink" controller="A" action="D">© 2016 Murat</anchor-box>
©2016穆拉特

从尝试中得到了结果?当你说“手动提供内部html文本”时,你的意思是想以javascript的方式进行吗?当我尝试提供内部文本时,它不会以某种方式显示在输出中。我感觉TagHelper在生成标记后删除了innerHtml。
    public override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
    {
        var content = output.GetChildContentAsync().Result.GetContent();

        var builder = new TagBuilder("a");
        builder.Attributes.Add("role", "button");
        builder.Attributes.Add("id", Name);
        builder.Attributes.Add("name", Name);
        output.Attributes.Add("data-controller", Controller);
        output.Attributes.Add("data-action", Action);

        builder.InnerHtml.Append(content);

        output.Content.SetContent(builder);

        return base.ProcessAsync(context, output);
    }
<anchor-box name="ALink" controller="A" action="D">© 2016 Murat</anchor-box>