Razor comment syntax

asp.net Mvc-3RazorComments

asp.net Mvc-3 Problem Overview


What is the syntax for server side comment in razor view?

I want to comment this code:

/*
@helper NavItem() {
  
}
*/

asp.net Mvc-3 Solutions


Solution 1 - asp.net Mvc-3

@* here is the code to comment *@

Solution 2 - asp.net Mvc-3

Both of the following work

@{
/*
    This is a comment
*/}


@//This is another comment

Update

With the new Beta of MVC 3 out the old methods of highlighting won't work.

@{
    //This is a comment
}

@{/*
      This is a multi
      line comment
*/}

@*
      This is a comment, as well
*@

Is the updated method @//This is a comment and @/* */ will no longer work.

Solution 3 - asp.net Mvc-3

Inside the .cshtml file, just press cntrl+k and cntrl+c, You will see the comment is automatically added by visual studio.(alternatively, cntrl_k and cntrl+u for uncommenting.) Or else if you want to write it manually then, just gohead with

@* Your Code *@

Solution 4 - asp.net Mvc-3

If its in your view, couldn't you use the standard HTML <!-- ... //--> or the .NET style <%-- .. --%>?

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionstackerView Question on Stackoverflow
Solution 1 - asp.net Mvc-3JarrettVView Answer on Stackoverflow
Solution 2 - asp.net Mvc-3BuildstartedView Answer on Stackoverflow
Solution 3 - asp.net Mvc-3Sanu Uthaiah BolleraView Answer on Stackoverflow
Solution 4 - asp.net Mvc-3Jonathan BatesView Answer on Stackoverflow