How do I change the class that is assigned to the control which is rendered by an MVC view by either the Html.TextBox or Html.ValidationMessage methods?
views:
34answers:
2
A:
It doesn't look like you can. It's defined as readonly in HtmlHelpers.cs. You could, of course, change the css. Or, make your own helper that names it what you want.
Mike Hildner
2010-08-10 21:23:15
+2
A:
You would do something like this (not that you have to escape "class" with @
because it's a reserved C# keyword):
Html.TextBox("Text", "Value", new { @class = "YourClassName" })
or if you don't like anonymous types:
Html.TextBox("Text", "Value", new Dictionary() { { "class", "YourClassName" } } )
marcind
2010-08-10 21:23:45