How to Add New Css Class in @Html. Textbox Mvc4

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

Try this

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

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest