NullDisplayTextResourceType is not taken into account by DataAnnotationsMetadataProvider.
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
ASP.NET Core 8.0 ignores NullDisplayTextResourceType in DataFormatAttribute:
```
[DisplayFormat(NullDisplayText = nameof(Resources.NullDate), NullDisplayTextResourceType = typeof(Resources))]
public DateTime? MyDate { get; set; }
...
MyDate: @Html.DisplayFor(m => m.MyDate)
```
The above code displays "MyDate: NullDate" instead of the actual string returned by Resources.NullDate.
The problem seems to be in [DataAnnotationsMetadataProvider.cs](https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.DataAnnotations/src/DataAnnotationsMetadataProvider.cs):
```
if (displayFormatAttribute != null)
{
displayMetadata.NullDisplayText = displayFormatAttribute.NullDisplayText;
// It should be displayMetadata.NullDisplayTextProvider = displayFormatAttribute.GetNullDisplayText;
}
```
See attached [WebApplication1.zip](https://github.com/dotnet/aspnetcore/files/13830407/WebApplication1.zip)
### Expected Behavior
DisplayFormatAttribute.NullDisplayTextResourceType should be taken into account.
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
8.0.100
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.