Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should my custom ASP.Net 5 MVC 6 Tag Helpers have an asp- prefix?

I've been reading about the new support for Tag Helpers in MVC 6 and now need to create my own. I see that the built in tag helpers for existing HTML elements are all prefixed with "asp-"

For example: <a asp-controller="Home" asp-action="Index">Home</a>

But what about my own custom tag helpers. Should I also prefix those with "asp-" to show that it is running on the server. Or should this be reserved for framework attributes? Should I create my own project/company named prefix instead?

Is there any guidance on this subject that I have missed?

like image 842
Rob Bird Avatar asked Sep 11 '15 21:09

Rob Bird


Video Answer


1 Answers

Tag helpers that target existing HTML elements should preface attribute names with a prefix that indicates the attribute is additive and run on the server. For example, the built in ASP.NET 5 Tag Helpers use the “asp-” prefix. The “asp-” prefix is not considered a reserved prefix, so developers can copy that convention. Some teams will prefer to use their own naming convention to distinguish their Tag Helpers.

If a Tag Helper targets a custom element then attributes should not be prefixed. Custom elements are processed only on the server, so you don’t need the prefix to denote server processing. A good example is the EnvironmentTagHelper. The following markup comes from the Views/Shared/_Layout.cshtml file created by a new ASP.NET web app.

<environment names="Development">

See also Authoring Tag Helpers

like image 156
RickAndMSFT Avatar answered Jan 18 '23 10:01

RickAndMSFT