I am new to this and created a custom attribute for string length validation on the server side. For example i have this
[StringLength(5, MinimumLength = 2, ErrorMessageResourceName = "StringLength", ErrormessageResourceType = typeof(Resource))]
public string LastName { get; set; }
and i want to create a custom attribute, so i can reduce the duplicates everytime i need to validate the string length
[MyStringLength(5)]
public string LastName { get; set; }
This is my view
@Html.TextBoxFor(model => model.LastName)
@Html.ValidationMessageFor(model => model.LastName)
My code for custom attribute "MyStringLength"
public class MyStringLengthAttribute : StringLengthAttribute
{
public MyStringLengthAttribute(int maximumLength) : base(maximumLength)
{
base.ErrorMessageResourceName = "StringLength";
base.ErrorMessageResourceType = typeof(Resource);
}
}
This helped me Modify default ErrorMessage for StringLength validation but after i post the form it just refreshes the page with the values and doesn't show any validation message