I am trying to override the max length error message in ASP.net MVC. Basically, I would like to make the error message string as follow:
[DisplayName] length should not be more than [x]. However, I do not know how to include the displayname attribute value inside.
public class MyMaxLengthAttribute : MaxLengthAttribute
{
public MyMaxLengthAttribute(int length) : base(length)
{
ErrorMessage = "What should I input here"
}
}
If you use the StringLengthAttribute
{0}
refers to the display name and {2}
refers to the length.
public class MyMaxLengthAttribute : StringLengthAttribute
{
public MyMaxLengthAttribute(int length) : base(length)
{
ErrorMessage = "{0} length should not be more than {2}"
}
}
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