Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What parameters does the stringlength attribute errormessage take?

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.

like image 553
Anders E. Andersen Avatar asked Nov 16 '12 22:11

Anders E. Andersen


People also ask

What is data annotation validator attributes in MVC?

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.

Which of the following attribute to used to validate string length choose the answer?

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.

Which of the following annotations specifies the maximum string length allowed by the database column?

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.

What is System ComponentModel DataAnnotations?

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.


1 Answers

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."

like image 198
Sergey Berezovskiy Avatar answered Oct 05 '22 23:10

Sergey Berezovskiy