Using ASP.NET MVC's default view engine, you can declare a server-side comment like this:
<%-- This is a comment --%>
This comment will only be visible on the server side and is not sent to the client. How would I do the same with the Razor view engine?
Razor View Engine has two types of comments, one is single-line and another is multiline. Razor uses the syntax "@* .. *@" for the comment block but in a C# code block we can also use "/* */" or "//".
In visual studio, select some code/markup in your razor view and press Ctrl+K, Ctrl+C, and it'll comment the selection as described above.
Note that in general, IDE's like Visual Studio will markup a comment in the context of the current language, by selecting the text you wish to turn into a comment, and then using the Ctrl + K Ctrl + C shortcut, or if you are using Resharper / Intelli-J style shortcuts, then Ctrl + / .
To comment in the code block of Razor view, we use the same syntax as we use in C#. Like for single line // and for multiline /* and */. To comment, HTML along with other code, we need to use razor comment block that starts with @* and ends with *@.
Start the comment block with @*
, end the comment block with *@
.
Similar to C# (/*
and */
)
@* single line comment *@
or
@* this is a comment this is another *@
More on Razor comments on the Gu's blog.
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