我的自定义ASP.Net 5 MVC 6标记帮助程序是否应具有asp前缀? [英] Should my custom ASP.Net 5 MVC 6 Tag Helpers have an asp- prefix?

查看:66
本文介绍了我的自定义ASP.Net 5 MVC 6标记帮助程序是否应具有asp前缀?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关MVC 6中对Tag Helpers的新支持的信息,现在需要创建自己的支持.我看到现有HTML元素的内置标记帮助程序都以"asp-"为前缀

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-"

例如: <a asp-controller="Home" asp-action="Index">Home</a>

但是我自己的自定义标签助手呢?我是否还应该在它们前面加上"asp-"以表明它正在服务器上运行.还是应该保留框架属性?我应该改为创建自己的项目/公司命名前缀吗?

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?

我错过了关于此主题的任何指导吗?

推荐答案

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.

如果标记帮助程序以自定义元素为目标,则属性不应添加前缀.自定义元素仅在服务器上处理,因此不需要前缀来表示服务器处理.一个很好的例子是EnvironmentTagHelper.以下标记来自由新ASP.NET Web应用程序创建的 Views/Shared/_Layout.cshtml 文件.

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">

另请参见创作标签助手

这篇关于我的自定义ASP.Net 5 MVC 6标记帮助程序是否应具有asp前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆