In a Razor page, creating an anonymous object (eg. for HtmlAttributes) starting with @class inside a @{} block creates these compiler errors
(void?): class" is a reserved word and cannot be used in implicit expressions. An explicit expression ("@()") must be used
and
CS0746: Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.
and
CS1525: Invalid expression term '='
Steps to reproduce the behavior:
services.AddRazorPages().AddRazorRuntimeCompilation();@{
var htmlAttributes = new { @class = "form-control" };
}
@{
var htmlAttributes = new { foo = "bar", @class = "form-control" };
}
You can use double @@

@fehrm Thanks for contacting us.
@NTaylorMullen The double @@ shouldn't be necessary as you are already inside a c# context, am I wrong? Otherwise @soeleman answer is correct.
Thanks for contacting us, @fehrm.
While this is a bug, it's super low pirority and we won't spend time fixing it, as the workaround is to simply use @@ per @soeleman's suggestion.