What is the difference in behavior of [MaxLength]
and [StringLength]
attributes?
As far as I can tell (with the exception that [MaxLength]
can validate the maximum length of an array) these are identical and somewhat redundant?
MaxLength is used for the Entity Framework to decide how large to make a string value field when it creates the database.
From MSDN:
Specifies the maximum length of array or string data allowed in a property.
StringLength is a data annotation that will be used for validation of user input.
From MSDN:
Specifies the minimum and maximum length of characters that are allowed in a data field.