How does the StringLengthAttribute work?
Keyword as follows:
class PartMetadata
{
// required keyword forces user to enter input
[Required]
[DisplayName("Part number")]
// or [Required(ErrorMessage="* Required")]
// ErrorMessage in string only enforces when data is entered
[StringLength(50, MinimumLength = 3, ErrorMessage = "* Part numbers must be between 3 and 50 character in length.")]
public string Number { get; set; }
Yes, that is the correct behavior. StringLength
verifies that a string is a certain length, but does not REQUIRE that the string be entered. Decorate Description with [Required], so that you have both a requirement for the string, and StringLength will provide the constraints on the string length.