How can I make a TagHelper render only plain text with no parent tag?

Viewed 429

How can I stop my TagHelper from rendering an outer tag?

e.g. I want something like:

<title>
    <translate>LoginPageTitle</translate>
</title>

...so the tag helper can get the translation from the database and render just:

<title>Login to Foobar</title>

I can't see how to do anything other than rename the original tag at all, but I don't want any tag at all.

Here's my current code:

public class TranslateTagHelper : TagHelper
{
    public string ResourceSet { get; set; } = "Global";

    public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
    {
        var content = await output.GetChildContentAsync();
        string originalContent = content.GetContent();

        output.Content.SetContent(@DbRes.T(originalContent, ResourceSet)); // Get translation from DB
    }
}
1 Answers

OK it turns out that all I needed was this:

output.TagName = null;

Related