【问题标题】:use @ in script code in MVC [duplicate]在MVC的脚本代码中使用@ [重复]
【发布时间】:2012-04-17 06:15:50
【问题描述】:

可能重复:
Escape @ character in razor view engine

如何在 MVC 页面(剃须刀引擎)的脚本代码中使用“@”符号

写这样的代码:

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

alert(a);
</script>

【问题讨论】:

    标签: asp.net-mvc-3 razor


    【解决方案1】:

    您可以使用两个 & 符号进行转义:@@

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

    顺便说一句,尽管我最近了解到并认为遇到这个问题的人也可能会发现它很有用:您可以使用安培符号和星号组合来执行 cmets:

    @*this would comment out some code, or just allow for comments in general*@
    

    【讨论】:

      【解决方案2】:

      @@ 应该可以转义字符

      【讨论】:

      • thx jrummell,下次我会尝试使用代码语法!
      【解决方案3】:
      var a = "this is a test text with "+<text>@</text>+" symbol";
      

      【讨论】:

        【解决方案4】:

        要转义 @ 符号,您需要将其加倍,如下所示:

        @@
        

        【讨论】:

          猜你喜欢
          • 2021-04-25
          • 2018-08-26
          • 2013-01-02
          • 2016-01-20
          • 2013-02-21
          • 1970-01-01
          • 2015-06-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多