How to fix problems with FoolProof Validation in mvc - Digital Tool Factory blog

How to fix problems with FoolProof Validation in mvc

For some reason the otherwise delightful nuget Package FoolProof Validation does not work with modern version of the entity framework – rather, the validation works just fine, but it chokes when you try to update the database with entity framework.

The workaround I found was to validate on a view model – and then translate that viewmodel to the actual model, which is then sent to the database.


Written By Steve French


One response to “How to fix problems with FoolProof Validation in mvc”

  1. Hi Steve!

    I found another solution about this problem

    For anyone looking for a solution to this for .Net 4. Grab a copy of the source code from and update the target platform to .Net 4 and add the following method to the ModelAwareValidationAttribute class.

    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;
    temp_26 = new string[1]
    string[] local_1 = temp_26;
    local_0 = new ValidationResult(this.FormatErrorMessage(validationContext.DisplayName), (IEnumerable)local_1);
    return local_0;

    the link of solution:


Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.