Tag Helpers - 自动关闭 HTML 标签是个坏习惯?
Tag Helpers - Self closing HTML tags is a bad habit?
我正在将 TagHelpers
合并到我的 MVC vNext 项目中,我意识到当我自行关闭 HTML 标签时它们不起作用。
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
<label asp-for="FirstName"/> <!-- self closing tag -->
<span asp-validation-for="FirstName"/> <!-- self closing tag -->
而且,当我放置结束标记时,我看到了显示的值。
<label asp-for="FirstName"></label>
<span asp-validation-for="FirstName"></span>
生成HTML
<label for="FirstName">FirstName</label>
<span class="field-validation-error" data-valmsg-for="FirstName" data-valmsg-replace="true">
<span id="FirstName-error" class="">The FirstName field is required</span>
</span>
我想知道的,它有什么区别?而且,自我关闭配对标签是一个坏习惯。如果你知道有什么文章讲到这个设计原则,请分享给我,不胜感激。
它们不起作用的原因是 "MVC tag helpers do not change whether an element is self-closing or not"(来自问题 #4475 中的评论)。
这是 ASP.NET 中的一个已知问题,计划在 VS IDE 中显示带有结束标记的非空元素的警告(参见问题 #398). One of ASP.NET developers commented in issue #1302 即:
"this is the current design but we have a few issues (open and closed) on the behaviour"
我正在将 TagHelpers
合并到我的 MVC vNext 项目中,我意识到当我自行关闭 HTML 标签时它们不起作用。
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
<label asp-for="FirstName"/> <!-- self closing tag -->
<span asp-validation-for="FirstName"/> <!-- self closing tag -->
而且,当我放置结束标记时,我看到了显示的值。
<label asp-for="FirstName"></label>
<span asp-validation-for="FirstName"></span>
生成HTML
<label for="FirstName">FirstName</label>
<span class="field-validation-error" data-valmsg-for="FirstName" data-valmsg-replace="true">
<span id="FirstName-error" class="">The FirstName field is required</span>
</span>
我想知道的,它有什么区别?而且,自我关闭配对标签是一个坏习惯。如果你知道有什么文章讲到这个设计原则,请分享给我,不胜感激。
它们不起作用的原因是 "MVC tag helpers do not change whether an element is self-closing or not"(来自问题 #4475 中的评论)。
这是 ASP.NET 中的一个已知问题,计划在 VS IDE 中显示带有结束标记的非空元素的警告(参见问题 #398). One of ASP.NET developers commented in issue #1302 即:
"this is the current design but we have a few issues (open and closed) on the behaviour"