Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Custom tag helper processing

$
0
0

Hi,

I have created a custom tag helper named "asp-disabled" with a target element set to "input" tag:

[HtmlTargetElement("input")]
public class AspDisabledTagHelper : TagHelper
{
    private const string AspDisabledAttributeName = "asp-disabled";

    [HtmlAttributeName(AspDisabledAttributeName)]
    public bool IsDisabled { set; get; }

    public override void Process(TagHelperContext context, TagHelperOutput output)
    {
        if (IsDisabled)
        {
            output.Attributes.Add(new TagHelperAttribute("disabled", "disabled"));
        }

        base.Process(context, output);
    }
}

Razor engine executes Process method for every encountered "input" tag, even if the latter doesn't have specified "asp-disabled" attribute. I'm wondering is this a correct behavior or am I missing something in tag declaration.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>