title: Get a Session value from my MVC app into my Javascript
body: <p>This isn't the standard, so please read before marking duplicate.</p>
  
  <p>In our MVC app at the top of our <code>_Layout.cshtml</code>, we load our scripts like this:</p>
  
  <pre><code>@Scripts.RenderFormat("&lt;script src='{0}' defer&gt;&lt;/script&gt;", "~/bundles/scripts")
  </code></pre>
  
  <p>At the bottom of <code>_Layout.cshtml</code> we have this:</p>
  
  <pre><code>@RenderSection("scripts", required: false)
  </code></pre>
  
  <p>For reasons outside of my control we must have the defer on that. :(</p>
  
  <p>This bundle includes the jquery files. One of the other files is called <code>Script.js</code>, which gets loaded after jQuery, and has a function called <code>setCollapse(collapse)</code>.</p>
  
  <p>It looks like this:</p>
  
  <pre><code>function setCollapse(collapse) {
      debugger;
      alert(collapse);
      if (collapse == 'False') {
          $('.collapse').collapse("show");
      } else {
          $('.collapse').collapse();
      }
  }
  </code></pre>
  
  <p>I would like to use a Session value with that javascript function on my MVC View load like this:</p>
  
  <pre><code>@section scripts
  {
      &lt;script&gt;
          $(document).ready(function() {
              debugger;
              var collapse = '@Session["Collapse"].ToString()';
              setCollapse(collapse);
          });
      &lt;/script&gt;
  }
  </code></pre>
  
  <p>But I continue to get: </p>
  
  <blockquote>
    <p>Uncaught ReferenceError: $ is not defined</p>
  </blockquote>
  
  <p>How can I get my Session value to get passed into my javascript/jQuery when the page loads?</p>