Html.TextBox("ParentPassword", "", new { @class = "required" })
what the gosh darned heck is the @ for the @class.
Html.TextBox("ParentPassword", "", new { @class = "required" })
what the gosh darned heck is the @ for the @class.
class
is a reserved keyword, so you can't use this as a variable name.
The @ operator allows you to get around this rule. The reason why its being done here is that the anonymous object is used to populate attributes on a HTML element. A valid attribute name is "class", which lets you set the CSS class on the element.
class
is a keyword. To use class
as the name of a variable/property, in C#, you can prepend @
to it, as @class
. In the IL, for all .net is concerned, the name of the variable/property is still class
- @
is the way you have to do it in C#.
Just to add my two cents to all the right answers here:
If you are new to C# but familiar to VB.NET, you probably know that there is a correspondent to @ in VB. The square brackets [ ] are used in VB.NET to surround a variable name that is named after a reserved word (or keyword). For example:
Dim [String] As String