简体   繁体   中英

Do All HTML attributes require a @ in ASP.NET MVC

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:

  1. Why does the HTML attribute disabled not have an @ symbol before it?
  2. Is the @ symbol not always required?
  3. Does the HTML attribute checked require an @ symbol?

Thank you

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM