I am working with asp.net mvc and creating a form. I want to add a class attribute to the form tag.
I found an example here of adding a enctype attribute and tried to swap out with class. I got a compile error when accessing the view.
I then found an example of someone adding a @ symbol to the beginning of the property name and that worked. Great that it works, but I am one that needs to know why and a quick Google search was not helpful. I understand that C# allows one to prepend the @ to a string to ignore escaping chars. Why does it work in this case? What does the @ tell the compiler?
Code that produces a compile error?
<% Html.BeginForm("Results", "Search",
FormMethod.Get, new{class="search_form"}); %>
Code that does work:
<% Html.BeginForm("Results", "Search",
FormMethod.Get, new{@class="search_form"}); %>
Go to Insert > Symbol > More Symbols. Go to Special Characters. Double-click the character that you want to insert. Select Close.
A plus symbol or a horizontal line crossing a vertical line is also a symbol used as an indication to increase, add, move down, or zoom in on software programs and hardware devices.
Go to Insert > Symbol. Pick a symbol, or choose More Symbols. Scroll up or down to find the symbol you want to insert. Different font sets often have different symbols in them and the most commonly used symbols are in the Segoe UI Symbol font set.
Text concatenation operator in Excel is the ampersand symbol (&). You can use it to join two or more text strings in a single string. The same result can be achieved by using the CONCATENATE function, and the following tutorial explains all the details: How to combine text strings, cells and columns in Excel.
In C#, 'class' is a reserved keyword - adding an '@' symbol to the front of a reserved keyword allows you to use the keyword as an identifier.
Here's an example straight out of the C# spec:
class @class {
public static void @static(bool @bool) {
if (@bool) System.Console.WriteLine("true");
else System.Console.WriteLine("false");
}
}
Note: this is of course an example, and not recommended practice.
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