如何在MVC 2中设置TextBox的MaxLength和Size?关于SO的问题已经提出了几个问题.作为MVC的新手,我发现没有一个解决方案似乎有效 - 可能是因为我做得不对.
无论如何,我想知道是否有更好的解决方案,因为之前的问题似乎是在MVC 2处于测试阶段时提出的.
这很容易,你只需要额外的htmlAtttributes
<%= Html.TextBoxFor(model => model.Member, new { maxlength = "20", width = "15" }) %>
<%= Html.TextBoxFor(model => model.Member, new { maxlength = "20", style = "width:200px;" }) %>
Run Code Online (Sandbox Code Playgroud)