Hemant Soni
Hemant Soni

Reputation: 2101

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?

Upvotes: 25

Views: 70755

Answers (3)

user3146115
user3146115

Reputation:

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"})

Upvotes: 2

Mario S
Mario S

Reputation: 11945

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.

Upvotes: 6

ssilas777
ssilas777

Reputation: 9804

Try this

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

Upvotes: 60

Related Questions