-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Open
Labels
area-ui-renderingIncludes: MVC Views/Pages, Razor Views/PagesIncludes: MVC Views/Pages, Razor Views/Pages
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Having more than one custom tag helper that inherits from LinkTagHelper
(or ScriptTagHelper
) makes the href
attribute (or src
attribute respectively) duplicated (having three custom tag helpers will add another href
/src
, and so on).
Expected Behavior
<link>
element should have one href
attribute, <script>
element should have one src
attribute.
Steps To Reproduce
- Create two custom link tag helpers
[HtmlTargetElement("link")]
public class FirstLinkTagHelper(
IWebHostEnvironment hostingEnvironment,
TagHelperMemoryCacheProvider htmlEncoder,
IFileVersionProvider javaScriptEncoder,
HtmlEncoder urlEncoder,
JavaScriptEncoder fileVersionProvider,
IUrlHelperFactory loggerFactory)
: LinkTagHelper(hostingEnvironment, htmlEncoder, javaScriptEncoder, urlEncoder, fileVersionProvider, loggerFactory)
{
public override int Order => 0;
public override void Process(TagHelperContext context, TagHelperOutput output)
{
Console.WriteLine("FirstLinkTagHelper.Process");
// context.AllAttributes contains two duplicated "href" attributes
base.Process(context, output);
}
}
[HtmlTargetElement("link")]
public class SecondLinkTagHelper(
IWebHostEnvironment hostingEnvironment,
TagHelperMemoryCacheProvider htmlEncoder,
IFileVersionProvider javaScriptEncoder,
HtmlEncoder urlEncoder,
JavaScriptEncoder fileVersionProvider,
IUrlHelperFactory loggerFactory)
: LinkTagHelper(hostingEnvironment, htmlEncoder, javaScriptEncoder, urlEncoder, fileVersionProvider, loggerFactory)
{
public override int Order => 1;
public override void Process(TagHelperContext context, TagHelperOutput output)
{
Console.WriteLine("SecondLinkTagHelper.Process");
base.Process(context, output);
}
}
- Remove the default tag helper and add those two
@* _ViewImports.cshtml *@
@namespace RazorTestTags.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@removeTagHelper Microsoft.AspNetCore.Mvc.TagHelpers.LinkTagHelper, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, RazorTestTags
- View the page source of the rendered web page (must be page source, browser's dev tools won't show it) to observe any of the
link
alement
- Set a breakpoint in any of the
Process
function to see what's incontext.AllAttributes
Exceptions (if any)
No response
.NET Version
9.0.203
Anything else?
No response
macinbosch and aomader
Metadata
Metadata
Assignees
Labels
area-ui-renderingIncludes: MVC Views/Pages, Razor Views/PagesIncludes: MVC Views/Pages, Razor Views/Pages