tags:

views:

32

answers:

1

How do you set the MaxLength and Size of a TextBox in MVC 2? There have been a couple of questions asked about this on SO. As a newcomer to MVC I am finding that none of the solutions appear to work - possibly because I am not doing it right.

In any case I am wondering if there are better solutions since the previous questions appear to be asked at a time when MVC 2 was in beta.

+2  A: 

It's easy, you just to have extra htmlAtttributes

<%= Html.TextBoxFor(model => model.Member, new { maxlength = "20", width = "15" }) %> 
<%= Html.TextBoxFor(model => model.Member, new { maxlength = "20", style = "width:200px;" }) %> 
ŁukaszW.pl
Amazing! They really did fix it after the Beta version. Even so, I found that only the second line worked in your solution. Also the solution only works for TextBoxFor and not EditorFor, although for now I am fine with that.
arame3333
You can pass like that any html attributes, but remember that they have to be valid for a specified html element that html helper generates - in this case it's input.
ŁukaszW.pl