ASP.NET MVC3 Razor - @* 做什么?

发布于 2024-10-15 12:51:39 字数 154 浏览 9 评论 0原文

因为在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二货你真萌 2024-10-22 12:51:39

@* 是服务器端注释:

如果您有这样的代码:

<p>
   /* comment 1 */
   @* comment 2 *@
   <!-- comment 3 --> 
   @{ /* comment 4 */ }
</p>

注释 1 将不起作用,因为您不在服务器模式下。该代码将被发送到浏览器,浏览器将显示它,因为 /* 不是 html 注释。

评论 3 也会发送给客户。我什至认为,如果它包含@块,它将在服务器上解析并执行。

评论 2 和 4 将不会通过线路发送。但是Nr 4有点难看。

@* is a server side comment:

If you have code like this:

<p>
   /* comment 1 */
   @* comment 2 *@
   <!-- comment 3 --> 
   @{ /* comment 4 */ }
</p>

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.

深海蓝天 2024-10-22 12:51:39

从:
http:// /www.asp.net/webmatrix/tutorials/2-introduction-to-asp-net-web-programming-using-the-razor-syntax

对于 ASP.NET Razor 注释,请以 @* 开头并以 *@ 结束。注释可以是一行或多行。

如果我理解正确的话, /* 仅适用于 <% %> 块内,因为 /* */ 是 C# 语法发表评论。您可以从 <% %> 块外部编写 @*
因此,与其写注释,不如

<% /* This is
a multiline comment */ %>

写成:

@* This is
a multiline comment *@

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

<% /* This is
a multiline comment */ %>

It can be written as:

@* This is
a multiline comment *@
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文