我正在尝试使用带有jquery的asp.net mvc 3无障碍javascript。
我正在关注此Tutorial
我不清楚如何做第一步。
我认为它只是覆盖了IsValid,但我一直收到错误所以我一定做错了什么
public class EmailAttribute : ValidationAttribute, IClientValidatable
{
public override bool IsValid(object value)
{
return base.IsValid(value);
}
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
yield return new ModelClientValidationEmailRule(FormatErrorMessage(metadata.GetDisplayName()));
}
}
public class ModelClientValidationEmailRule : ModelClientValidationRule
{
public ModelClientValidationEmailRule(string errorMessage)
{
base.ErrorMessage = errorMessage;
base.ValidationType = "email";
}
}
我收到此错误
IsValid(object value) has not been implemented by this class. The preferred entry point is GetValidationResult() and classes should override IsValid(object value, ValidationContext context).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotImplementedException: IsValid(object value) has not been implemented by this class. The preferred entry point is GetValidationResult() and classes should override IsValid(object value, ValidationContext context).
Source Error:
Line 13: public override bool IsValid(object value)
Line 14: {
Line 15: return base.IsValid(value);
Line 16: }
Line 17:
答案 0 :(得分:6)
IsValid方法应包含验证逻辑。
您只是调用IsValid的基类实现,它似乎抛出了NotImplementedException,因为它应该在子类中被重写。
public override bool IsValid(object value)
{
//return true if 'value' is a valid email. Otherwise return false.
}