我正在尝试使用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:

最佳答案

IsValid方法应包含您的验证逻辑。

您只是在调用IsValid的基类实现,它似乎引发了NotImplementedException,因为它有望在子类中被覆盖。

public override bool IsValid(object value)
{
    //return true if 'value' is a valid email. Otherwise return false.
}

10-07 19:22
查看更多