6

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?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

1 Answers1

10

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.

Community
  • 1
  • 1
djdd87
  • 67,346
  • 27
  • 156
  • 195