Wednesday 20 February 2013

MVC StringLength and maxlength

When you add the validation StringLength in MVC, it won't automatically limit the user to the max length.  You need to manually to add this in the View.

You cannot use @Html.EditorFor and you should use @Html.TextBoxFor.


<%=Html.TextBox("polNum",null, new {maxlength=10}) %>

@Html.TextBoxFor(model => model.homePostalCode, new { maxlength = 7 })

No comments:

Post a Comment