Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 1.21 KB

aspnet-asp.net-validationcontext.membername-is-null-sometimes.md

File metadata and controls

34 lines (23 loc) · 1.21 KB

ASP.NET ValidationContext.MemberName is not NULL when using custom DataAnnotations.ValidationAttribute

Version Introduced

4.8

Change Description

In .NET Framework 4.7.2 and earlier versions, when using a custom xref:System.ComponentModel.DataAnnotations.ValidationAttribute?displayProperty=nameWithType, the xref:System.ComponentModel.DataAnnotations.ValidationContext.MemberName?displayProperty=nameWithType property returns null. In .NET Framework 4.8, it returns the member name.

Recommended Action

The default behavior of the xref:System.ComponentModel.DataAnnotations.ValidationContext.MemberName?displayProperty=nameWithType property remains the same. To retrieve a valid value from the ValidationContext.MemberName property, add the following setting to your app config file:

    <configuration>
      <appSettings>
      ...
        <add key="aspnet:GetValidationMemberName"  value="true"/>
      ...
      </appSettings>
    </configuration>

Affected APIs

  • P:System.ComponentModel.DataAnnotations.ValidationContext.MemberName

Category

ASP.NET