Pregunta

im using foolproof validation for hours

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

it validates the fields correctly but when i call submitchanges in the controller it throws me an error

[NotImplementedException: No se puede implementar el método o la operación.] Foolproof.ModelAwareValidationAttribute.IsValid(Object value) +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: An unexpected exception was thrown during validation of 'end' when invoking Foolproof.GreaterThanAttribute.IsValid. See the inner exception for details.]

happens the same with dates, what can i do? is there any other way to do this validation?

¿Fue útil?

Solución

seems that foolproof doesnt have integration with EF4 or higher, to fix that you must download the whole Foolproof project and overdrive the "isvalid" method in the ModelAwareValidationAttribute class them build it and reference the dll to your project.

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+

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top