Solving “Conditional Compilation is turned off” in mvc3 razor

I was getting this “Conditional Compilation is turned off” when I was getting value from ViewBag in JavaScript in view.
See sample JavaScript bellow which will get this error.

$(function () {
         $(this).ready(function() {
        var Id = @ViewBag.Id;
        if (Id != null) {
            // some logic here.
        }
    }); 

I got this “Conditional Compilation is turned off” error on “@ViewBag.Id” due to which my javascript was not getting executed.
Solution to this was very simple.
After searching for some time I found that I can use JavaScript eval() function for executing @ViewBag.Id.
So I just replaced var Id = @ViewBag.Id; line with var Id = eval(‘@ViewBag.Id;’);

admin