Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you declare a comment using the Razor view engine? [duplicate]

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?

like image 947
Daniel T. Avatar asked Dec 17 '10 03:12

Daniel T.


People also ask

How do you comment on Razor view?

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 "//".

How can you comment using Razor syntax in MVC?

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.

How do you write a comment on a view?

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 + / .

How do you add comments in Cshtml?

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 *@.


1 Answers

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.

like image 65
RPM1984 Avatar answered Sep 23 '22 23:09

RPM1984