3

I'm using MVC Foolproof validation (https://foolproof.codeplex.com/) and I've realised that it doesn't allow for multiple targets on the attributes. For example, I'd like to have a property that is required to be "GreaterThanOrEqualTo" two other properties, but the Foolproof attributes are not set up for multiple usage. So this:

public class RecordResultViewModel
{
    [LessThanOrEqualTo("EndDate", ErrorMessage = "The start date cannot be after the end date.")]
    [LessThanOrEqualTo("EnrolmentEndDate", ErrorMessage = "The start date cannot be before the enrolment end date.")]
    public DateTime? StartDate { get; set; }

    [GreaterThanOrEqualTo("StartDate", ErrorMessage = "The end date cannot be before the start date.")]
    [GreaterThanOrEqualTo("EnrolmentStartDate", ErrorMessage = "The end date cannot be before the enrolment start date.")]
    public DateTime? EndDate { get; set; }

    public DateTime EnrolmentStartDate { get; set; }
    public DateTime EnrolmentEndDate { get; set; }
}

I can't think of any way around this and I've noticed that the project on Codeplex hasn't been maintained since 2012, so I really need an alternative solution that supports multiple same attributes and also supports ALL of the same validation attributes as Foolproof.

Nick Coad
  • 3,623
  • 4
  • 30
  • 63
  • 4
    Try [FluentValidation](https://github.com/JeremySkinner/FluentValidation) – Simon C Apr 13 '15 at 04:02
  • Have you tried a custom validator with multiple fields? something like this http://byatool.com/mvc/custom-data-annotations-with-mvc-how-to-check-multiple-properties-at-one-time/ but with an array of properties. – nramirez Apr 13 '15 at 04:15
  • I suggest you to implement your own validator http://stackoverflow.com/questions/8906228/how-to-validate-one-field-related-to-anothers-value-in-asp-net-mvc-3 – nramirez Apr 13 '15 at 04:24
  • @SimonC I think your comment is probably my best bet - looks simple enough. Thanks! (and thanks to all others who commented also) – Nick Coad Apr 13 '15 at 05:02

0 Answers0