在MVC中的脚本代码中使用@

MHF*_*MHF 4 razor asp.net-mvc-3

可能重复:
在razor视图引擎中转义@字符

如何在MVC页面(razor引擎)中的脚本代码中使用"@"符号

写一个这样的代码:

<script>
var a = "this is a test text with @ symbol";

alert(a);
</script>
Run Code Online (Sandbox Code Playgroud)

Gra*_*mas 5

您可以使用两个ampersat符号逃脱:@@.

var a = "this is a test text with @@ symbol";
Run Code Online (Sandbox Code Playgroud)

顺便说一句,虽然我最近学到并认为遇到这个问题的人也会发现它很有用:你可以用ampersat标志和星号组合做评论:

@*this would comment out some code, or just allow for comments in general*@
Run Code Online (Sandbox Code Playgroud)