-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Tag Helpers: Add "asp-" prefix to all custom attributes on Tag Helpers that target traditional HTML elements #1618
Comments
What's the rationale for not prefixing helpers that create new custom elements? Isn't there still ambiguity on whether a given piece of markup is server-side or client-side? |
Good idea. Especially angular devs wont like it without a prefix. |
Maybe make the prefixes configurable by naming convention like angular directives do. asp-whatever would be written AspWhatever in angular. This makes it more flexible for component vendors. |
@StuartQ honestly, because that's my personal preference right now. Like anything, that could still change. We're still considering adding support for specifying a prefix when you import Tag Helpers (aspnet/Razor#88) which would let you add your own prefix to custom elements too (although right now it would also mean you'd have to prefix the @mbeckenbach the naming convention of HTML element/tag names is already being tracked at aspnet/Razor#240 |
Please please don't prefix the tag names!! But I personally would use asp:attribute="" syntax, because it shows a little bit better that this attribute is evaluated by ASP, and that it's is not maybe an self invented "HTML 5" attribute that I want to evaluate by some jquery selector magic "Find all elements with an attribute which begins with asp-". I hope you know what I mean. And for own namespaces I go for this solution:
This is extremely sexy! |
Using prefixes is a good standard. But I think that they should be customizable and optional if someone would like that. That is my preference. What guidelines should be used is up to the community to decide. |
May I name write my attribute like [HtmlAttributeName("@controller")] so i would use it as <form @controller="Home">
</form> I want to differentiate among Razor, Html and Angular attributes. because while reading other developers code it will creates confusion for me. Last time my developer wrote the same attribute data-sum-field and utilize the same attribute for both javascirpt (jquery) and angular, the only way to recognize was to check the angular directive as injected or not. One more question, If I have two third party TagHelper for anchor tag and both take "action" attribute one for href and second for theme, what will happened? Sometime open source have the same names. |
@sheryever you won't be able to use All this is going to do is interfere with the Razor parser, that takes It is something we spent a lot of time thinking about, and realized it is not something reasonably achievable at least not for RTM. |
- update XML docs to reflect new HTML / custom attribute separation - update `Exception` messages to use new attribute names - update MVC tag helper sample to use new custom attribute names - add missing `<input/>` tag helper `throw`s test nits: - reword a few comments and messages for clarity and consistency - use `<exception/>` sections to describe what's thrown - add "Reviewers" comments about current throws - note `<a/>` and `<form/>` are slightly inconsistent with others: `throw` if unable to override specified `href` or `action` attributes; rest `throw` only if custom attributes are inconsistent e.g. `<input/>` with `asp-format` but no `asp-for` - create test tag helpers after all property values are available
- update XML docs to reflect new HTML / custom attribute separation - update `Exception` messages to use new attribute names - update MVC tag helper sample to use new custom attribute names - add missing `<input/>` tag helper `throw`s test nits: - reword a few comments and messages for clarity and consistency - use `<exception/>` sections to describe what's thrown - add "Reviewers" comments about current throws - note `<a/>` and `<form/>` are slightly inconsistent with others: `throw` if unable to override specified `href` or `action` attributes; rest `throw` only if custom attributes are inconsistent e.g. `<input/>` with `asp-format` but no `asp-for` - create test tag helpers after all property values are available
commit 27beca7 |
@yishaigalatzer, OKh, No problem, I will take Tag Helper as Html Tag Helper not Razor MVC Tag Helper at least till RTM. Well, overall the work is really great 👍 |
We're changing our guidance and convention such that Tag Helpers that target existing HTML elements should prefix any attributes they add or where they change the semantic meaning of an existing HTML attribute. Tag Helpers that effectively create new custom elements (e.g.
<cache>
#1552) will not be prefixed, neither their tag name or attribute names. We may introduce support for defining an element prefix via the@addtaghelper
directive in the future (aspnet/Razor#88).We'll update the following Tag Helpers:
FormTagHelper
InputTagHelper
LabelTagHelper
SelectTagHelper
ScriptTagHelper
AnchorTagHelper
Example
Example Before Change
Example After Change
The text was updated successfully, but these errors were encountered: