Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional compilation turned off warning when mixing razor and javascript

The following snippet triggers a "Conditional compilation turned off" warning in one of my views. Do you have an idea on how to fix it?

<script type="text/javascript">
    $(document).ready(function () {
        @RenderSection("JQueryDocumentReady",false)
    });
</script>

I tried to insert a semicolon at the end of the render section statement but it didn't help.

Thank you.

like image 799
nakhli Avatar asked Jul 24 '11 14:07

nakhli


1 Answers

NOTE: Answer accepted because of alternative suggestion to the question, not solution given for the problem in title.

I'm not 100% sure what Conditional Compilation has to do with being in a <script> block, but I did find that wrapping the statements in parenthesis fixed the problem.

@(RenderSection("JQueryDocumentReady"))

I do think this method has a bit of code smell though. It's not a problem to just have a script section and assign things to document ready on each page. It really isn't going to save you much work, and it will force you to put javascript on views outside of script tags the way you have chosen to do it.

like image 136
Nick Larsen Avatar answered Oct 22 '22 00:10

Nick Larsen