Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IsValid(object value) has not been implemented by this class

I am trying to use asp.net mvc 3 unobstructed javascript with jquery.

I am following this Tutorial

I am unclear how to do step one.

I thought it was just overriding IsValid but I keep getting an error so I must be doing something wrong

 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";
            }
        }

I get this error

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: 
like image 832
chobo2 Avatar asked Jan 30 '11 01:01

chobo2


1 Answers

The IsValid method should contain your validation logic.

You are just calling the base class implementation of IsValid, which seems to be throwing a NotImplementedException because it is expected to be overridden in the sub class.

public override bool IsValid(object value)
{
    //return true if 'value' is a valid email. Otherwise return false.
}
like image 102
Peter Hansen Avatar answered Sep 28 '22 01:09

Peter Hansen