Reputation: 181
Today I noticed strange behaviour of ASP.NET Core taghelper when testing validation messages.
I have no jquery-validate and jquery-validate-unobtrusive in place.
This works fine:
<span asp-validation-for="Name" class="text-danger"></span>
This is not working:
<span asp-validation-for="Name" class="text-danger" />
Any idea why?! Is this a bug?
Thanks for your inputs!
Upvotes: 0
Views: 360
Reputation: 10889
@Jonathan is correct - this an invalid element to be self-closing. Making a tag self-closing indicates that it is a void element - meaning the tag has no content inside of it. Span tags totally have content!
However, the reason it doesn't work in Core is because what happens on this line. With a self-closing tag, the TagMode
property on the output
variable is set to SelfClosing
, and the TagBuilder
isn't going to put any of the message content in to it (because it is a void element which has no content).
With a </span>
at the end, the mode changes to StartTagAndEndTag
and content is properly added.
Upvotes: 1