MrM MrM - 1 year ago 114
C# Question

How do I limit the length of characters in a textbox in MVC?

I would like to limit a textbox to 10 characters in MVC.

<label ID="lbl2" runat="server" Width="20px"></label>
<%=Html.TextBox("polNum") %>
<label ID="lbl1" runat="server" Width="10px"></label>

I know you can set the Max Length property in .net. How do I do that in MVC with a textbox generated this way?

Answer Source

You need to set some html properties... something like:

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

good luck

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download