Html.TextBox("ParentPassword", "", new { @class = "required" })
Html.TextBox(“ParentPassword”,“”,new {@class =“required”})
what the gosh darned heck is the @ for the @class.
对于@class来说,什么是gosh darned heck是@。
3 个解决方案
#1
20
class
is a reserved keyword, so you can't use this as a variable name.
class是保留关键字,因此您不能将其用作变量名。
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.
@运算符允许您绕过此规则。它在这里完成的原因是匿名对象用于填充HTML元素的属性。有效的属性名称是“class”,它允许您在元素上设置CSS类。
#2
8
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#.
class是一个关键字。要使用class作为变量/属性的名称,在C#中,可以将@作为@class添加到它之前。在IL中,对于所有.net而言,变量/属性的名称仍然是类 - @是您必须在C#中执行它的方式。
#3
7
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:
如果你是C#的新手但对VB.NET很熟悉,你可能知道VB中有一个@的通讯员。方括号[]在VB.NET中用于包围以保留字(或关键字)命名的变量名。例如:
Dim [String] As String
#1
20
class
is a reserved keyword, so you can't use this as a variable name.
class是保留关键字,因此您不能将其用作变量名。
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.
@运算符允许您绕过此规则。它在这里完成的原因是匿名对象用于填充HTML元素的属性。有效的属性名称是“class”,它允许您在元素上设置CSS类。
#2
8
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#.
class是一个关键字。要使用class作为变量/属性的名称,在C#中,可以将@作为@class添加到它之前。在IL中,对于所有.net而言,变量/属性的名称仍然是类 - @是您必须在C#中执行它的方式。
#3
7
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:
如果你是C#的新手但对VB.NET很熟悉,你可能知道VB中有一个@的通讯员。方括号[]在VB.NET中用于包围以保留字(或关键字)命名的变量名。例如:
Dim [String] As String