I'm using Visual Studio 2012 RC with ASP.NET MVC 4. This is driving me crazy, and I know this has been asked several times, but I can't find a solution for MVC 4, and no unified solution for MVC 3. I must be missing something...
All I want to do is output a c# variable in a block of javascript. This should be trivial, and is a necessity to be able to do, but despite all of the workaround/hacks I've tried, nothing will get rid of the "Conditional compilation is turned off " error. This would be fine if it was just a warning, but it's an error. If I close the view inside of visual studio it compiles and works fine, but if it's open I can't even compile, and that isn't acceptable.
I've tried using /*@cc_on @*/ and /*@("@cc_on @")*/ to turn conditional compilation on to no avail. Doing @(serverVar) gives an invalid character error (@). I've also tried @Html.Raw and several other things.
The only way I include razor code without an error is if the razor code is inside quotes, which works well for strings, but not for int and bool.
@{
int serverVar = 5;
}
<script>
var obj = { jsVar: @serverVar };
</script>
I've searched everywhere for this, and can't find an agreed upon solution. Am I missing something? Any help is greatly appreciated.
var obj = { jsVar: 5 };as the script body.