limiting the no. of characters entered in textbox html helper element in asp.net mvc 2.0
I am using a order form as follows, <%using (Ajax.BeginForm("AddToCart", "../ShoppingCart", null, new AjaxOptions { OnSuccess = "handleUpdate", OnBegin = "ajaxValidate" }, new { @class = "AddToCartForm" })) { %>
Thanks in advance,
And i also restrict they cannot order more th开发者_如何学Can 2*10^31-1 or 32-bit signed integers can hold.
The best way to do this in MVC 2 is to take advantage of the inbuilt validation by using data annotations.
For the Quantity field you should use the Range annotation.
Here is a great post to walk you through it, and if you follow it to the end he covers using jquery to do the client side validation too.
Use MaxLength="Number of characters you wish user should enter" in your code ..
as
<%=Html.TextBoxFor(model => Model.Count, new {MaxLength="10"})%>
精彩评论