2011-01-30 5 views
6

asp.net mvc 3 jqueryで妨げられないjavascriptを使用しようとしています。IsValid(オブジェクト値)はこのクラスで実装されていません

私はステップ1を行う方法は不明だこの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: 

答えて

5

あなたの検証ロジックが含まれている必要がありisValidメソッド。

サブクラスでオーバーライドされることが予想されるため、NotImplementedExceptionをスローしているように見える、IsValidの基本クラスの実装を呼び出すだけです。

+0

なぜ彼らがIsValidを抽象メソッドにしていないのか不思議です。誰もそれを説明できますか? –

関連する問題