剃刀评论语法

sta*_*ker 112 comments razor asp.net-mvc-3

在razor视图中服务器端注释的语法是什么?

我想评论这段代码:

/*
@helper NavItem() {

}
*/
Run Code Online (Sandbox Code Playgroud)

Jar*_*ttV 198

@* here is the code to comment *@
Run Code Online (Sandbox Code Playgroud)

  • 在visual studio中,在剃须刀视图中选择一些代码/标记,然后按Ctrl + K,Ctrl + C,它将如上所述评论选择. (34认同)

Bui*_*ted 43

以下两项工作

@{
/*
    This is a comment
*/}


@//This is another comment
Run Code Online (Sandbox Code Playgroud)

更新

随着MVC 3的新Beta版的出现,旧的突出显示方法将无效.

@{
    //This is a comment
}

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

@*
      This is a comment, as well
*@
Run Code Online (Sandbox Code Playgroud)

是更新的方法@//This is a comment,@/* */将不再有效.

  • 实际上,它仍然是正确的,但他们添加了一个新的`@**`语法.所以现在有三种评论方式.不仅仅是JarretV的那个. (2认同)

小智 7

在.cshtml文件中,只需按cntrl + kcntrl + c,您将看到注释由visual studio自动添加.(或者,cntrl_kcntrl + u用于取消注释.)或者如果你想手动编写那么,只是傻瓜

@* Your Code *@
Run Code Online (Sandbox Code Playgroud)