Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i stop a Tag Helper automatically being used?

For example: I want my tag to render as-is. Instead it is auto generating all the other goodies with it. How do i turn off Tag Helpers for that one specific tag?

like image 342
Stark Avatar asked Mar 26 '18 19:03

Stark


2 Answers

You can add a ! before the tag name to prevent the tag helper from executing:

<!form method="post">
    <button type="submit">Submit</button>
</!form>

Source

like image 84
Henk Mollema Avatar answered Sep 20 '22 18:09

Henk Mollema


You can remove a specific TagHelper from impacting a view by referencing its full type name, i.e.:

@removeTagHelper The.Full.TypeName.Of.The.TagHelper, TheAssemblyNameTheTagHelperExistsIn

Alternatively if you want to disable all TagHelpers in an assembly:

@removeTagHelper *, TheAssemblyNameTheTagHelperExistsIn

So to come full circle, if you want to disable all default MVC TagHelpers you can include the two lines:

@* This nukes ~/ resolution and ITagHelperComponents (things running on body/head), this is an auto-inclusion in every view *@
@removeTagHelper *, Microsoft.AspNetCore.Mvc.Razor

@* These TagHelpers are typically included via a _ViewImports.cshtml. This nukes all of the MVC TagHelpers (environment, input with asp-for, etc.)*@
@removeTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
like image 21
N. Taylor Mullen Avatar answered Sep 20 '22 18:09

N. Taylor Mullen