In the MVC4 template one of the data annotation attributes used is stringlength.
For example:
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
What parameters {0}, {1}, {2} (more?) are legal?
Edit: To be more specific, I can see from the example and trial and error what the possibilities are, but I would like to see some hard documentation.
I can't find anything about this in the StringLengthAttribute documentation.
Data annotation attributes are attached to the properties of the model class and enforce some validation criteria. They are capable of performing validation on the server side as well as on the client side. This article discusses the basics of using these attributes in an ASP.NET MVC application.
The StringLength Attribute Specifies both the Min and Max length of characters that we can use in a field. StringLength is somewhat similar to MaxLength and MinLength attribute but operates only on string type properties.
Data Annotations - StringLength Attribute in EF 6 & EF Core It specifies the maximum characters allowed for a string property which in turn sets the size of a corresponding column ( nvarchar in SQL Server) in the database.
Data annotations (available as part of the System. ComponentModel. DataAnnotations namespace) are attributes that can be applied to classes or class members to specify the relationship between classes, describe how the data is to be displayed in the UI, and specify validation rules.
The {0}
index is the display name of property, {1}
is the MaximumLength
, {2}
is the MinimumLength
. So, your error message will be formate as "The Foo must be at least 6 characters long."
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