diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationMessageTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationMessageTagHelper.cs index 8858623013..6af41687db 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationMessageTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ValidationMessageTagHelper.cs @@ -71,11 +71,13 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu }; } + var childContent = await output.GetChildContentAsync(); + var tagBuilder = Generator.GenerateValidationMessage( ViewContext, For.ModelExplorer, For.Name, - message: null, + message: childContent.IsEmptyOrWhiteSpace ? null : childContent.GetContent(), tag: null, htmlAttributes: htmlAttributes); @@ -89,7 +91,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu // We check for whitespace to detect scenarios such as: // // - var childContent = await output.GetChildContentAsync(); + if (childContent.IsEmptyOrWhiteSpace) { // Provide default message text (if any) since there was nothing useful in the Razor source.