您好我正在尝试创建下一个简单的自定义验证:
public class EnteroDistintoDeAttribute : ValidationAttribute, IClientValidatable
{
public int entero { set; get; }
public EnteroDistintoDeAttribute(int entero)
{
this.entero = entero;
}
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if(entero == (int)value)
{
return new ValidationResult(Res_Errors.errorDistinto);
}
return ValidationResult.Success;
}
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
yield return new ModelClientValidationRule
{
ErrorMessage = this.ErrorMessage,
ValidationType = "EnteroDistintoDe"
};
}
}
并像这样使用它:
[EnteroDistintoDe(0)]
[Required]
public int scheduledIdPersonaSeleccionada { get; set; }
但我不断收到下一个错误:
错误 1 属性参数必须是属性参数类型的常量表达式、typeof 表达式或数组创建表达式