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.