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