I am having trouble understanding the validation logic that validates DataNotation data:
With the following model:
[AlwaysInvalid]
public class TestModel
{
[Required]
public string Test { get; set; }
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public class AlwaysInvalidAttribute : ValidationAttribute
{
private readonly object typeId = new object();
public AlwaysInvalidAttribute() : base("Fail !") {}
public override object TypeId { get { return this.typeId; } }
public override bool IsValid(object value)
{
return false;
}
}
The AlwaysInvalidAttribute error message is displayed only if the required attribute is valid: I cannot receive both messages at the same time. Has anyone understood why? I think this is a problem with DefaultModelBinder, but still not found where and why.
source
share