Blankman
Blankman

Reputation: 267020

adding a css class with Html.TextBox

Trying to add a 'class' html attribute, but I think the keyword 'class' is causing issues.

<%: Html.TextBox("name", "value", new {class: " required "})%>

Is there a workaround?

Upvotes: 6

Views: 6342

Answers (1)

djdd87
djdd87

Reputation: 68476

Just prefix 'class' with an '@' as it's a reserved keyword.

<%: Html.TextBox("name", "value", new { @class: " required "})%>

If you need some background on the @ keyword, this is a good SO question to read.

Upvotes: 10

Related Questions