views:

34

answers:

2

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?

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
+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