即时使用万无一失的验证
[Required]
[Range(typeof(TimeSpan), "00:00:00", "23:59:59")]
public Nullable<System.TimeSpan> start { get; set; }
[Required]
[GreaterThan("HoraInicio")]
public Nullable<System.TimeSpan> end { get; set; }
它可以正确验证字段但是当我在控制器中调用submitchanges时会抛出错误
[NotImplementedException:No se puede implementarelmétodopolaoperación。] Foolproof.ModelAwareValidationAttribute.IsValid(对象值)+59 System.ComponentModel.DataAnnotations.ValidationAttribute.IsValid(Object value,ValidationContext validationContext)+115 System.ComponentModel.DataAnnotations.ValidationAttribute.GetValidationResult(Object value,ValidationContext validationContext)+29 System.Data.Entity.Internal.Validation.ValidationAttributeValidator.Validate(EntityValidationContext entityValidationContext,InternalMemberEntry property)+198
[DbUnexpectedValidationException:在调用Foolproof.GreaterThanAttribute.IsValid时,在'end'验证期间抛出了意外异常。有关详细信息,请参阅内部异常。]
与日期相同,我该怎么办?还有其他方法可以进行此验证吗?
答案 0 :(得分:2)
似乎万无一失并没有与EF4或更高版本集成,以解决您必须下载整个Foolproof项目并过度驱动ModelAwareValidationAttribute类中的“isvalid”方法,他们构建它并将dll引用到您的项目中。
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var container = validationContext.ObjectInstance;
#region This block of code decompiled from namespace System.ComponentModel.DataAnnotations.ValidationAttribute
ValidationResult local_0 = ValidationResult.Success;
if (!this.IsValid(value, container)) // Change to decompiled code here to call our abstract implementation instead of the NotImplemented IsValid(object value) method above
{
string[] temp_26;
if (validationContext.MemberName == null)
temp_26 = (string[])null;
else
temp_26 = new string[1]
{
validationContext.MemberName
};
string[] local_1 = temp_26;
local_0 = new ValidationResult(this.FormatErrorMessage(validationContext.DisplayName), (IEnumerable<string>)local_1);
}
return local_0;
#endregion}
http://foolproof.codeplex.com/SourceControl/latest http://forums.asp.net/t/1752975.aspx?Conditional+validation+with+MVC+Foolproof+Validation+