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

末鹿安然 提交于 2019-12-04 07:47:22

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

Each TagHelper targets one or more specific HTML elements or custom tags.

for example take a look AnchorTagHelper, You can see, TargetElementAttribute is used to associate this TagHelper with the standard HTML a element:

[HtmlTargetElement("a", Attributes = ActionAttributeName)]
//...
public class AnchorTagHelper : TagHelper

So your custom tag helper have its own pre-fixes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!