How can I set MAXLENGTH on input fields automatically?
Posted
by Gary McGill
on Stack Overflow
See other posts from Stack Overflow
or by Gary McGill
Published on 2010-03-17T16:55:44Z
Indexed on
2010/03/17
21:11 UTC
Read the original article
Hit count: 403
I'm using ASP.NET MVC RC2. I have a set of classes that were auto-generated "Linq-to-SQL Classes", where each class models a table in my database. I have some default "edit" views that use the neat-o Html.TextBoxFor
helper extension to render HTML input fields for the columns in a table.
However, I notice that there is no MAXLENGTH
attribute specified in the generated HTML. A quick google shows that you can add explicit attributes using TextBoxFor
etc. but that would mean that I need to hard-code the values (and I need to remember to do it for every input).
This seems pretty poor, considering that everything was automatically generated directly from the DB, so the size of the columns is known. (Although, to be fair, the web-side stuff has to work with any model objects, not just with Linq-to-SQL objects).
Is there any nice way of getting this to do the right thing?
© Stack Overflow or respective owner