Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify class attribute of password box in Razor

Does anybody know how to specify class html attribute of password box in Razor?

Here is what I currently have but it throws errors:

@Html.PasswordFor(x => x.Password, new { id="pbPassword", class="loginPassword" })

Thanks

like image 968
Allan Chua Avatar asked Jun 19 '13 00:06

Allan Chua


2 Answers

class is a keyword to declare a new class in C#. So you must add @ in this case.

Try this:

@Html.PasswordFor(x => x.Password, new { id="pbPassword", @class="loginPassword" })
like image 194
Iswanto San Avatar answered Oct 04 '22 04:10

Iswanto San


Class is a reserved word so you need to prepend it with an "@" to distinguish it from the reserved word, e.g.

@Html.PasswordFor(x => x.Password, new { id="pbPassword", @class="loginPassword" })
like image 33
Turnkey Avatar answered Oct 04 '22 03:10

Turnkey