25

I have used following code to add css class with @Html.TextBox but this is only working for @Html.TextBoxFor and not for @Html.TextBox.

@Html.TextBox("ticket_new_attachment_attributes_0_description", new { @class= "bigfield"})

What am I missing?

3 Answers 3

60

Try this

@Html.TextBox("ticket_new_attachment_attributes_0_description", null, new { @class= "bigfield"})
Sign up to request clarification or add additional context in comments.

1 Comment

This code does work, but note that Mario Sannum gives a reason as to why in his answer below. The second parameter is value, the third parameter is for attributes.
6

The second parameter is the value.
You need to use overload with the third parameter for html attributes, like so:

// Pass null (or the value) as second parameter
@Html.TextBox("ticket_new_attachment_attributes_0_description", null, new { @class = "bigfield"})

See the msdn reference.

Comments

2

For @Html.TextBox second parameter is textbox value so, you can pass "" as textbox value and third parameter is Html attributes

Try below html :

@Html.TextBox("ticket_new_attachment_attributes_0_description", "", new { @class= "bigfield"})

1 Comment

This question was asked 3y ago... And currently has best answer.

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.