I have created a separate class library to hold all my model objects. This is due to there being two sites, but needing the same model objects and validation that comes with it. Instead of copying and pasting the code in two places I thought I could just add the to a library. Everything looks great apart from MaxLength, it won't show up when I add System.ComponentModel.DataAnnotations
Yes, I have added a reference but nothing seems to get it to work like it does in a web solution.
Try to use [StringLength(40, ErrorMessage = "Name cannot be longer than 40 characters.")]
because this attribute generates client-side unobtrusive JS validation rules too.
Try StringLength instead. StringLength is for model validation, whereas MaxLength is for Entity Framework to decide how large to make a string field in the database.
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