title: How to get to Model or Viewbag Variables in a Script Tag
body: <p><em>Vs'12 asp.net C# MVC4 - Int.Appl.Template EF Code First</em></p>
  
  <p>Here is my very simple <code>Script</code></p>
  
  <pre><code>&lt;script class="TractsScript"&gt;
  
       $('#Add').click(function (e) {
  
           var val = @ViewBag.ForSection;
           alert(val);
  
       });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>As per example I am wanting to simply set a variable in my <code>script</code> or USE a <code>Viewbag.</code> or <code>Model.</code></strong></p>
  
  <p>I haven't been able to find an answer in any of the following forums: <a href="https://stackoverflow.com/questions/4599169/using-razor-within-javascript">StckTrace1</a>,<a href="https://stackoverflow.com/questions/5770578/get-value-from-model-inside-jquery-script">StackTraceBetterAnswer</a></p>
  
  <p>Other Things i have tried:</p>
  
  <pre><code>var model = @Html.Raw(Json.Encode(Model))
  alert(model.Sections);
  alert(@ViewBag.ForSection);
  </code></pre>