本文介绍了IsValid(对象值)尚未由此类实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将asp.net mvc 3畅通无阻的javascript与jquery一起使用.

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

我正在关注教程

我不清楚该怎么做.

我以为这只是覆盖IsValid,但我不断收到错误消息,所以我必须做错了什么

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

我收到此错误

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方法应包含您的验证逻辑.

The IsValid method should contain your validation logic.

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

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.
}

这篇关于IsValid(对象值)尚未由此类实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 05:37