diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/DefaultHtmlGenerator.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/DefaultHtmlGenerator.cs index d06ded41b6..0b9a75e282 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/DefaultHtmlGenerator.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/DefaultHtmlGenerator.cs @@ -419,11 +419,6 @@ public virtual TagBuilder GenerateLabel( } } - if (string.IsNullOrEmpty(resolvedLabelText)) - { - return null; - } - var tagBuilder = new TagBuilder("label"); var fullName = NameAndIdProvider.GetFullHtmlFieldName(viewContext, expression); var idString = NameAndIdProvider.CreateSanitizedId(viewContext, fullName, IdAttributeDotReplacement); diff --git a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs index 0d36d43a3a..6233cb4d94 100644 --- a/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs @@ -977,6 +977,25 @@ protected virtual IHtmlContent GenerateLabel( return HtmlString.Empty; } + // Do not generate an empty