views:

163

answers:

3

I have the following tag in my MVC Application. How can I apply a class to my textbox?

<%= Html.TextBox("username", "", new { maxlength = 50 })%>
+10  A: 
<%= Html.TextBox("username", "", new { maxlength = 50, @class = 'your-classname' })%>

Then in your CSS file you would use this selector:

.your-classname { ...css rules here... }
Doug Neiner
A: 

assuming the class name of the input box is "username" then use:

input[type=text].username {
  /* styles here */
}
fernyb
A: 

Based on your code, I believe the Html.TextBox helper method will also automatically create an id from the name field:

id="username"

You could then access the text box via CSS with:

#username {
    /* styles */
}
DM