Reputation: 97
I have the following tag in my MVC Application. How can I apply a class to my textbox?
<%= Html.TextBox("username", "", new { maxlength = 50 })%>
Upvotes: 0
Views: 665
Reputation: 1847
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 */
}
Upvotes: 0
Reputation: 983
assuming the class name of the input box is "username" then use:
input[type=text].username {
/* styles here */
}
Upvotes: 0
Reputation: 66221
<%= Html.TextBox("username", "", new { maxlength = 50, @class = 'your-classname' })%>
Then in your CSS file you would use this selector:
.your-classname { ...css rules here... }
Upvotes: 10