Javascript global variable when using Scripts.Render MVC4

Viewed 7301

I have an MVC 4 project that utilizes javascript bundling.

In my _Layout.cshtml page I have something like this:

    @Scripts.Render("~/bundles/scripts/desktop/modernizr",
        "~/bundles/scripts/desktop/jquery","~/bundles/scripts/desktop/jqueryui",
        "~/bundles/scripts/desktop/jqueryvalidation", "~/bundles/scripts/custom")

There are others, but this is just an example. Within one of my scripts that's called in the custom script I need to reference a global variable that set within the ready function, as shown below:

  <script type="text/javascript">                   
     $(function () {            
         //alert('Page is ready!');
         var warning = 10;
         var timeout = 20;   }); </script>     

Problem is, I always seem to get an error within the method that requires the warning and timeout variables. Am I missing something obvious (not to me, though!) on how I should create these variables? Should I var them outside the $Ready, because the js is loading before the page is technically ready?

Where should the global variable go, if everything is already in a render bundle and there are no script blocks?

Thanks!

2 Answers
Related