【问题标题】:ASP.NET Core validation tag helper strange behaviourASP.NET Core 验证标记助手奇怪的行为
【发布时间】:2017-02-27 00:14:57
【问题描述】:

今天我注意到测试验证消息时 ASP.NET Core taghelper 的奇怪行为。

我没有 jquery-validate 和 jquery-validate-unobtrusive。

这很好用:

<span asp-validation-for="Name" class="text-danger"></span>

这不起作用:

<span asp-validation-for="Name" class="text-danger" />

知道为什么吗?! 这是一个错误吗?

感谢您的意见!

【问题讨论】:

标签: jquery asp.net validation asp.net-core asp.net-core-mvc


【解决方案1】:

@Jonathan 是正确的 - 这是一个无效的自动关闭元素。使标签自动关闭表明它是void element - 意味着标签内部没有内容。 Span 标签完全有内容!

但是,它在 Core 中不起作用的原因是 because what happens on this line。使用自闭合标签,output 变量上的TagMode 属性设置为SelfClosing,并且TagBuilder 不会将任何消息内容放入其中(因为它是空的没有内容的元素)。

&lt;/span&gt; 结尾,模式更改为 StartTagAndEndTag 并正确添加内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-02
    • 1970-01-01
    • 2019-05-22
    相关资源
    最近更新 更多