From b206e5b2d1f889065e8b2bdeeb02095f7a51f8f5 Mon Sep 17 00:00:00 2001 From: "kishan.anem" Date: Sun, 15 Jul 2018 12:53:16 +0530 Subject: [PATCH] Custom error messages with validation message tag helper #8035 #8035 --- .../ValidationMessageTagHelper.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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.