我有一个自定义数据验证属性我创建,以确保用户输入的密码是相同的,但从不调用IsValid.
自定义属性:
public class IsSameAsAttribute : ValidationAttribute
{
public String TargetProperty { get; set; }
private readonly object _typeId = new object();
public IsSameAsAttribute(string targetProperty)
{
TargetProperty = targetProperty;
}
public override bool IsValid(object value)
{
return false;
//Type objectType = value.GetType();
//bool isValid = false;
//PropertyInfo[] neededProperties =
// objectType.GetProperties().Where(propertyInfo => propertyInfo.Name == TargetProperty).ToArray();
//return isValid;
}
public override object TypeId
{
get { return _typeId; }
}
}
Run Code Online (Sandbox Code Playgroud)
它适用的数据模型:
public class RegistrationData
{
[Required(ErrorMessage = "First Name Required")] …Run Code Online (Sandbox Code Playgroud)