I am working on a project that declares html attributes as @class = "className" or @id = "ID" however for this form control it does not happen:
@Html.CheckBoxFor(Model => Model.IsEBSCreated, new { disabled = "disabled" })
Questions:
- Why does the HTML attribute
disabled
not have an@
symbol before it? - Is the
@
symbol not always required? - Does the HTML attribute
checked
require an@
symbol?
Thank you
CodePudding user response:
- The
@
prefix on an identifier in C# allows language keywords to be used as identifiers, aka verbatim identifier. - Read this: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/verbatim
- Note that you don't need to use
@
with C#'s contextual keywords likefrom
andwhere
- only C#'s reserved keywords.
Why does the HTML attribute
disabled
not have an@
symbol before it?
Because disabled
is not a C# language keyword.
Is the
@
symbol not always required?
Only when you're using a C# language keyword as an identifier.
Does the HTML attribute
checked
require an@
symbol?
Yes, because checked
(and unchecked
) are C# language keywords.
For example:
public interface @interface
{
string? @string { get; }
}
public class @class : @interface
{
private static readonly string? @null = null;
string? @interface.@string => @null;
}
Feel free to use the above code in a team project if you happen to dislike a particular member of your team.