How do i set the min and max annotation on a Property, with Data Annotations Extensions?
This is what i have tried:
[Required(ErrorMessage = "Dette felt er påkrævet!")]
[Digits(ErrorMessage = "Indtast kun cifre")]
[Min(8, ErrorMessage = "Brugernavnet skal være 8 tegn langt.")]
[Max(8, ErrorMessage = "Brugernavnet skal være 8 tegn langt.")]
[Display(Name = "Brugernavn")]
public string UserName { get; set; }
I get the following error:
Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: range
Min and Max are for decimal types. For strings you use the [StringLength]
or the [RegularExpression]
attributes:
[StringLength(8, MinimumLength = 8)]
public string UserName { get; set; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With