Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Attributes property used for in a HtmlTargetElement attribute

The way an attribute is set on an asp.net core tag helper is as follows:

[HtmlTargetElement("test1",Attributes = "make",ParentTag = "myparent")]

I'm not understanding the syntax Attributes = "make"

I know Attributes is a string that gets passed into the constructor of HtmlTargetElement but what I don't get is the = "make" part. If this were the call list of the method I now that would mean make is the value if null is passed in but I don't understand it when it's on the call method side.

What is the Attributes property used for in a HtmlTargetElement attribute?

like image 418
Peter Kellner Avatar asked Dec 05 '25 15:12

Peter Kellner


1 Answers

The HtmlTargetElement attribute is used to specify additional criteria for a TagHelper to use when determining a match. The Attributes property specifies that an html element must contain that value to match. The attribute:

[HtmlTargetElement("test1",Attributes = "make")]``

Would match the following element:

<test1 make></test1>

Also keep in mind that you can decorate a class with multiple [HtmlTargetElement] attributes to result in a logical-OR.

For more examples see this

For official documentation of HtmlTargetElement.Attributes see here

like image 100
Strake Avatar answered Dec 07 '25 05:12

Strake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!