Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8179695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:03:29+00:00 2026-06-07T00:03:29+00:00

The error generated is Conditional Compilation is turned off. Conditional Compilation hack from MSDN

  • 0

The error generated is “Conditional Compilation is turned off”.

Conditional Compilation hack from MSDN is prevalent but fails.

There are several questions like this one:
Conditional Compilation is turned off in Razor?

They all point to the answer of:

/*@cc_on @*/

From the article seen here at the MSDN:

http://msdn.microsoft.com/en-us/library/5y5529x3(v=vs.90).aspx

However, this hack is pretty fail or I seem to fail at implementing it. The trailing @* causes the remaining code in the .cshtml file to become commented out. Moreover, @cc_on gives an error “cc_on does not exist in the current context”.

Here is a piece of code to test in a .cshtml file:

<script type="text/javascript">
 @for(int i = 0; i < 5; i++)
 {
    document.write(@i);
 }
</script>

Which will cause the “Conditional Compilation is turned off” message. Attempting to insert the workaround in there will cause various other messages such as “cc_on” does not exist in the context”, “expected ,”, or “expected ;”, or “expected )” from the for loop.

How can a razor for loop be used in a javascript script tag?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:03:30+00:00Added an answer on June 7, 2026 at 12:03 am

    Try surrounding your js with <text></text>

    <script type="text/javascript">
     @for(int i = 0; i < 5; i++)
     {
        <text>var that = this;</text>
     }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When developing a .Net web application, if a run time error is generated, it
This is the full error report that is generated when tried to compile my
Update : The error seems to be generated by this line: *line = color;
I get this 'error' when running PEVerify on a custom generated assembly. [MD](0x8013124C): Error:
@Override public void onCancel() { // TODO Auto-generated method stub ERROR:The method onCancel() of
The following code: with open(J:\\python\\.data) as data: self.data=pickle.load(data) generated the following error: File J:\python\code.py,
Problem: gem generate fails because it's missing XML Builder. $ gem generate ERROR: While
Is there a best practice for managing php.ini configurations from development to production? Obviously
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\list(1194): error C2451: conditional expression of type 'void' is
In certain error conditions I would like to redirect to the Home controller but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.