Ok, I cant find the answer to this:
<%: Html.ActionLink("Click Here", "Action", null, new {class="myClass"})%>
I want to set the CSS class attribute of the generated element.
Obviously, C# will not allow me to use "class" as the name of an object's member.
What should I do?
Essentially an anonymous type is a reference type and can be defined using the var keyword. You can have one or more properties in an anonymous type but all of them are read-only.
Anonymous types in C# are the types which do not have a name or you can say the creation of new types without defining them. It is introduced in C# 3.0. It is a temporary data type which is inferred based on the data that you insert in an object initializer.
From the perspective of the common language runtime, an anonymous type is no different from any other reference type, except that it cannot be cast to any type except for object.
We can't use a anonymous typed variable as a parameter for a method. But we can pass anonymous type for a method that accept dynamic type. Example: public class Employee.
Can You try with escaping the class with : @.
So, please modify your code to :
<%: Html.ActionLink("Click Here", "Action", null, new {@class="myClass"})%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With