Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

TagHelper attributes with data- have surprising behavior #342

@rynowak

Description

@rynowak

Consider the following:

@{ var pwnt = "Hello, world!"; }
<p data-th-color="color: red; @pwnt">
            This should be red.
</p>


[TargetElement("p", Attributes = "data-th-color")]
    public class ColorTagHelper : TagHelper
    {
        [HtmlAttributeName("data-th-color")]
        public string Color { get; set; }

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.Attributes.Add("style", Color);
        }
    }

Inside the taghelper, the value of Color is "Hello, world!" instead of the expected "color: red; Hello, world!". According to @NTaylorMullen this is because razor has special handling of data-* attributes.

Changing the attribute to something that doesn't begin with data- will give the expected behavior.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions