我正在开发一个应用程序,以从日历中验证出生日期。根据所选日期,它应显示over 18
或under 18
。执行时出现错误:
mscorlib.dll中发生了'System.FormatException'类型的异常,但未在用户代码中处理。其他信息:输入字符串的格式不正确。
以下是我尝试过的内容:
public class DOBvalidator: ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
int givenAge = int.Parse(value.ToString());
if (givenAge < 18)
{
return new ValidationResult("The age must be greater than 18");
}
else
{
return ValidationResult.Success;
}
}
}
这个问题可能是什么原因?