New attribure Between comparing to two properties

Aug 8, 2011 at 3:39 PM

I have tried to create following member

        [DataMember]
        [Date(ErrorMessage = "Enter valid date")]
        [GreaterThanOrEqualTo("DATE_MIN", ErrorMessage = "Date must be from actual year")]
        [LessThanOrEqualTo("DATE_MAX", ErrorMessage = "Date must be from actual year")]
        [Display(Name = "Date to")]
        [DataType(DataType.Date)]
        public DateTime? DATUM_TO { get; set; }

but use thi is not possible, giving me this error: "Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: is"

is is possible to add two parameter atrribute like this ?

        [DataMember]
        [Date(ErrorMessage = "Enter valid date")]
        [BetweenOrEqualTo("DATE_MIN", "DATE_MAX", ErrorMessage = "Date must be from actual year")]
        [Display(Name = "Date to")]
        [DataType(DataType.Date)]
        public DateTime? DATUM_TO { get; set; }

thanks

kubiix

Coordinator
Aug 9, 2011 at 2:35 PM

The first example really should work - this seems to only be a problem with unobtrusive. I'll look into.

In the mean time, you could make a custom validation attribute to take care of it. See:

http://www.nickriggs.com/posts/build-model-aware-custom-validation-attributes-in-asp-net-mvc-2/

Jun 26, 2014 at 3:00 PM
I still does not seem to work with both LessThan and GreaterThan attributes on the same field work with the unobtrusive validation. I am trying to modify the Foolproof code to work with the both attributes. So far I have gotten to the point where I am overriding the ClientTypeName on LessThanAttribute to return something else then "is", however haven't found how the javascript should be changed in order to make this work. My app is not failing, but my validation is not working, the unobtrusive JS is not triggered.
Jan 7, 2015 at 6:43 AM
Has this issue been solved?

I am experiencing the same issue, with the latest lib of foolproof validation, and MVC5. Below is how i am adding this validation.

[RequiredIfTrue("ReadingRequired"]
[RequiredIfNot("OptionChoiceId", 2]
public string UserComments {get; set;}

When the field is rendered in view, it throws an exception:

The following validation type was seen more than once: requiredif

Any fix or Update so far?