views:

155

answers:

2

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

Here is the code that I want to comment:

/*
@helper NavItem() {

}
*/
A: 

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

Jonathan Bates
`<%-- --%>` will still output to the client btw
BuildStarted
The contents don't, but I have found that the whitespace is still reserved in the output.
Jonathan Bates
Well, when processed by the Razor view engine it's output just like any other "html" element. So you won't see the content because it's not rendered by the browser. But it's still output in full. (based on my experience with razor and just tested it really quick)
BuildStarted
Good to know, I will make note of it.
Jonathan Bates
I just tested this (with Preview 1), ASPX comments `<%-- --%>` _seem_ to work, even though this is the Razor engine, not the WebForms/ASPX engine. However, more testing reveals that Razor ignores anything within _any_ ASP tags `<% %>` (but conserves whitespace?). Code within standard HTML comments `<!-- -->` is still run and output, only the client will ignore its contents.
Lucas
+8  A: 

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
*/}

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

BuildStarted
Also, @/* ... */ should work.
anurse
Good point - I will make a note of it. Thanks :)
BuildStarted
Why the vote down? Please comment as it's been updated with the changes in Razor Beta
BuildStarted