ValidationContext.MemberName is set incorrectly in the DataAnnotationsModelValidator · Issue #120 · aspnet/AspNetWebStack (original) (raw)
Problem Description
My customer creating custom validation class which deliveerd from System.ComponentModel.DataAnnotations.ValidationAttribute.
Using this in .NET4.7.1 ASP.NET Web API 2.0, ValidationContext.MemberName is set "DisplayName".
This is problem for custom class because they can not know MemberName without this property.
- Expected behavior
ValidationContext.MemberName is "TestValue3" - Actual behavior
ValidationContext.MemberName is "Display name From 'DisplayAttribute'"
TestValue3 is set "DisplayAttribute".
public class TestModel
{
[Validations.CustomValidation]
public string TestValue1 { get; set; }
[Validations.CustomValidation(ErrorMessage = "ErrorMessage: {0} ErrorMessage")]
public string TestValue2 { get; set; }
[Validations.CustomValidation(ErrorMessage = "ErrorMessage: {0} ErrorMessage")]
[Display(Name = "Display name From 'DisplayAttribute'")]
public string TestValue3 { get; set; }
public string Message { get; set; }
}