Use Comments in Asp.Net MVC Razor View Example

Commenting in Razor view is a little different than c# comments. In C#, we use (“//") for commenting, but in Razor, we will define comments like ("@*  *@"). 

The syntax for Commenting in Razor View

The syntax of comments in razor view will be like as shown below. 


@* This is a Razor multiline comment *@

This razor view syntax (“ @*  *@") tell that code inside this should be ignored from being executed. This syntax is common for both and c# language using Razor. 

Shortcut to Comment Block

The shortcut for Razor Commenting is similar to the C# shortcut that would be as shown. 


Comment the block - ( Ctrl E, C)

Uncomment the block - ( Ctrl E, U)


The following examples will show how to use razor comments in MVC applications.


The following example shows how to use comments in the mvc razor view. 









Following is another example to use comments in mvc razor view 


This way, we can use comments in razor view applications in mvc.