Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 493
Blankman Avatar asked Jun 14 '10 14:06

Blankman


1 Answers

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.

like image 199
djdd87 Avatar answered Oct 16 '22 03:10

djdd87