Search code examples
javascriptasp.net-mvc-3razorconditional-comments

Conditional compilation error/warning when using razor syntax in javascript (cc_on does not exist in this context)


I am using Razor syntax in an ASP.NET MVC3 View inside a JavaScript code but I get a "conditional compilation is off" warning. I searched for it and found out that using /*@cc_on @*/ before the code turns it on. But I get an error "The name 'cc_on' does not exist in the current context". Any ideas? Where exactly am I supposed to give /*@cc_on @*/ ?

Sample Code:

<script type ="text/javascript">
     @*
          - some multi-line comment stuff here
          - apparently the at signs cause syntax errors --argh!
     *@ 
</script>

Solution

  • Let me just guess... Try the following:

    /*@("@cc_on @")*/
    

    or

    @("/*@cc_on @*/")
    

    whatever you prefer

    I hope it's correct Razor syntax. An idea is to render this value as a string as @ is used by razor (in your case compiler thinks that you want to output @cc_on variable which isn't declared)