I use the MVC3 Razor engine to generate views and has the following line of code generating a text field
@Html.EditorFor(model => model.AddressLine1)
In the corresponding model, I use the data annotation attribute to limit the number of valid characters to 55:
[StringLength(55)] public string AddressLine1 { get; set; }
However, this allows the user to enter a longer address, which must then be transmitted via a validation message when trying to submit the form. How can I limit the text box to 55 characters so that the user cannot enter it anymore?
If I generated the text field myself, I would use the maxlength attribute for the input type, but I'm not sure how to achieve the same results using the Html.EditFor method.
Sperick
source share