When create new MVC5 application, there is a ViewModel with this property:
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "New password")]
public string NewPassword { get; set; }
I'm interesting in this part:
ErrorMessage = "The {0} must be at least {2} characters long."
I believe that {0}
gets string from [Display(Name = "New password")]
and {2}
gets string from MinimumLength = 6
.
What I don't understand, is why they are in this particular order? I mean why exactly {2}
and not, say, {1}
gets value from MinimumLength = 6
? The same question for {0}
. How can I determine this order?
Is next declaration would be correct? I expect that {0}
gets display name and {1}
- length: 25
.
[MinLength(length: 25, ErrorMessage = "Length of {0} must be at least {1} characters long.")]
[Display(Name = "My property")]
public string MyProperty { get; set; }
What would be if I remove attribute [Display(Name = "My property")]
? Does {0}
in that case just takes name of my property "MyProperty"
?
Thanks.