0

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

<%= Html.TextBox("username", "", new { maxlength = 50 })%>
1
  • 2
    You have what appears to be a correct answer - accept it? Commented Nov 25, 2009 at 21:20

3 Answers 3

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

Then in your CSS file you would use this selector:

.your-classname { ...css rules here... }
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

0

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 */
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.