diff --git a/src/Microsoft.AspNet.Mvc.DataAnnotations/DataAnnotationsMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.DataAnnotations/DataAnnotationsMetadataProvider.cs index 4baad584d7..52ecc70bac 100644 --- a/src/Microsoft.AspNet.Mvc.DataAnnotations/DataAnnotationsMetadataProvider.cs +++ b/src/Microsoft.AspNet.Mvc.DataAnnotations/DataAnnotationsMetadataProvider.cs @@ -75,7 +75,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata displayMetadata.Description = () => displayAttribute.GetDescription(); } - // DisplayFormat + // DisplayFormatString if (displayFormatAttribute != null) { displayMetadata.DisplayFormatString = displayFormatAttribute.DataFormatString; @@ -87,6 +87,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata displayMetadata.DisplayName = () => displayAttribute.GetName(); } + // EditFormatString if (displayFormatAttribute != null && displayFormatAttribute.ApplyFormatInEditMode) { displayMetadata.EditFormatString = displayFormatAttribute.DataFormatString; @@ -233,8 +234,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata var display = field.GetCustomAttribute(inherit: false); if (display != null) { + // Note [Display(Name = "")] is allowed. var name = display.GetName(); - if (!string.IsNullOrEmpty(name)) + if (name != null) { return name; } diff --git a/test/Microsoft.AspNet.Mvc.DataAnnotations.Test/DataAnnotationsMetadataProviderTest.cs b/test/Microsoft.AspNet.Mvc.DataAnnotations.Test/DataAnnotationsMetadataProviderTest.cs index 3c9b3d57dd..721d8a44b2 100644 --- a/test/Microsoft.AspNet.Mvc.DataAnnotations.Test/DataAnnotationsMetadataProviderTest.cs +++ b/test/Microsoft.AspNet.Mvc.DataAnnotations.Test/DataAnnotationsMetadataProviderTest.cs @@ -424,7 +424,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata typeof(EnumWithDisplayNames), new List> { - new KeyValuePair("cero", "0"), + new KeyValuePair(string.Empty, "0"), new KeyValuePair(nameof(EnumWithDisplayNames.One), "1"), new KeyValuePair("dos", "2"), new KeyValuePair("tres", "3"), @@ -436,7 +436,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata typeof(EnumWithDisplayNames?), new List> { - new KeyValuePair("cero", "0"), + new KeyValuePair(string.Empty, "0"), new KeyValuePair(nameof(EnumWithDisplayNames.One), "1"), new KeyValuePair("dos", "2"), new KeyValuePair("tres", "3"), @@ -708,7 +708,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata [Display(ShortName = "uno")] One = 1, - [Display(Name = "cero")] + [Display(Name = "")] Zero = 0, [Display(Name = "menos uno")]