gpt4 book ai didi

c# - IsValid(object value) 尚未被此类实现

转载 作者:太空狗 更新时间:2023-10-29 21:36:30 26 4
gpt4 key购买 nike

我正在尝试将 asp.net mvc 3 无障碍 javascript 与 jquery 一起使用。

我正在关注这个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.
}

关于c# - IsValid(object value) 尚未被此类实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4840567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com