System.ComponentModel.DataAnnotations MaxLength not showing

I created a separate class library to store all the model objects. This is due to the fact that there are two sites, but they need the same model objects and validations that are attached to it. Instead of copying and pasting the code in two places, I thought I could just add it to the library. Everything looks great separately from MaxLength, it will not be displayed when adding System.ComponentModel.DataAnnotations

Yes, I added the link, but nothing seems to work as in the web solution.

+4
source share
2 answers

Try using [StringLength(40, ErrorMessage = "Name cannot be longer than 40 characters.")] Because this attribute also creates unobtrusive client-side JS validation rules.

+9
source

Try StringLength. StringLength is used to validate the model, while MaxLength for the Entity Framework determines how large the row size is in the database.

+3
source

All Articles