开发者

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" })) { %>

  • <%=Html.Label("Quantity")%> <%=Html.TextBoxFor(model => Model.Count)%>

  • <% } %> Now if i entered a large no of t-shirts like 999999999999999999999999999999999999 the Form was unresponsive.So i should limit the no of characters entered in the textbox.So please tell me how to set this limitation so as to not having integer overflow.

    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"})%>     
    
    0

    上一篇:

    下一篇:

    精彩评论

    暂无评论...
    验证码 换一张
    取 消

    最新问答

    问答排行榜