What parameters does the stringlength attribute errormessage take?

Anders E. Andersen picture Anders E. Andersen · Nov 16, 2012 · Viewed 13.3k times · Source

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.

Answer

Sergey Berezovskiy picture Sergey Berezovskiy · Nov 16, 2012

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