locked
Conditional Compilation Is Turned Off RRS feed

  • Question

  • User-2064956551 posted

    I am using below line of code in a Razor View Inside Jquery Code block and I am seeing the error "Conditional Compilation Is Turned Off".

    I am using MVC3. Is there any way to get around this error?

    Thanks in advance.

     var t = @System.Configuration.ConfigurationManager.AppSettings["t"];

    Thursday, September 29, 2011 7:30 PM

Answers

  • User-2064956551 posted

    I have figured out the problem i have inserted double quotes around the razor view code in javascript and it started working.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 30, 2011 1:24 PM

All replies

  • User1904378495 posted

    It's considered bad practice to access any resources directly from the view. Instead have you the controller action method read that value and pass it to the view via the ViewBag.

    For example . The controller:

    public ActionResult Index(){
      var t = System.Configuration.ConfigurationManager.AppSettings["t"];
      ViewBag.t = t;
      return View();
    }

     Then in the View: 

    <div>
       @ViewBag.t
    </div>

    By doing it this way the view is isolated from any other system interactions and it becomes easier to change where the configuration comes from.

    Thursday, September 29, 2011 7:40 PM
  • User-2064956551 posted

    CodeHobo,

    I have changed my code as per the best practice you have suggested but the problem is in my Javascript code when try to use @Viewbag.t or @ViewBagVariable i am still getting the "Conditional Compilation Is Turned Off" error.

    Do you have any suggestions to get around "Conditional Compilation Is Turned Off" error?

     

    Thank You.

     

    Friday, September 30, 2011 12:44 PM
  • User-2064956551 posted

    I have figured out the problem i have inserted double quotes around the razor view code in javascript and it started working.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 30, 2011 1:24 PM
  • User961513815 posted

    var xyz = "@ViewBag.t";

    alert(xyz);

    Saturday, July 14, 2012 12:46 PM