ASP.NET MVC3 Razor - @* 做什么?
因为在 Google 中搜索标点符号非常困难...
我知道在 Razor 中 @
启动一个代码块,但是 @*
是做什么的呢?据我在 VS 中所知,它启动了一个评论块。如果这与 /*
不同,那又如何呢?
Since it's pretty difficult to search Google for punctuation...
I know in Razor that @
starts a code block, but what does @*
do? As far as I can tell in VS, it starts a comment block. If that's different from /*
, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@* 是服务器端注释:
如果您有这样的代码:
注释 1 将不起作用,因为您不在服务器模式下。该代码将被发送到浏览器,浏览器将显示它,因为 /* 不是 html 注释。
评论 3 也会发送给客户。我什至认为,如果它包含@块,它将在服务器上解析并执行。
评论 2 和 4 将不会通过线路发送。但是Nr 4有点难看。
@* is a server side comment:
If you have code like this:
comment 1 will not work, because you are not in server mode. That code will be send to the browser, and the browser will show it, because /* is not an html comment.
Also comment 3 will be sent to the client. And I even think, it will be parsed and executed on the server if it contains @ blocks.
Comment 2 and 4 will not be send over the line. but Nr 4 is a bit ugly.
从:
http:// /www.asp.net/webmatrix/tutorials/2-introduction-to-asp-net-web-programming-using-the-razor-syntax
对于 ASP.NET Razor 注释,请以 @* 开头并以 *@ 结束。注释可以是一行或多行。
如果我理解正确的话,
/*
仅适用于<% %>
块内,因为/* */
是 C# 语法发表评论。您可以从<% %>
块外部编写@*
。因此,与其写注释,不如
写成:
From:
http://www.asp.net/webmatrix/tutorials/2-introduction-to-asp-net-web-programming-using-the-razor-syntax
For ASP.NET Razor comments, you start the comment with @* and end it with *@. The comment can be on one line or multiple lines.
And if I understand you correctly the
/*
only applies from within a<% %>
block because/* */
is C# syntax for a comment. You can write@*
from outside a<% %>
block.So instead of writing comments like
It can be written as: