title: Error with pushing C# variables to JavaScript
body: <p>I would like to see my controller's variables in the <code>window</code> JavaScript object. I mean, globally, for particular View. For this, I have the following code in the controller: </p>
  
  <pre><code>    public async Task&lt;IActionResult&gt; Create()
      {
          ViewBag.AdvertiserOptions = await _advertiserRepository.Advertisers.ToListAsync();
          ViewBag.CategorieOptions = await _categoryRepository.Categories.ToListAsync();
  
          return View();
      }
  </code></pre>
  
  <p>And on the view I have the following (to catch variables):</p>
  
  <pre><code>@section Scripts
  {
      &lt;script&gt;
          window.ManuallySending.advertiser_options = 
              JSON.parse(@JsonConvert.SerializeObject(ViewBag.AdvertiserOptions));
  
          window.ManuallySending.category_options = 
                      JSON.parse(@JsonConvert.SerializeObject(ViewBag.CategorieOptions));
  
      &lt;/script&gt;
  }
  </code></pre>
  
  <p>It gives me the following error: </p>
  
  <p><a href="https://i.stack.imgur.com/NUdvi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NUdvi.png" alt="enter image description here"></a></p>
  
  <p>And in the JS console in my browser: </p>
  
  <blockquote>
    <p>Uncaught SyntaxError: Unexpected token &amp;</p>
  </blockquote>
  
  <p>I'm using <code>newtonsoft json</code> library. Here is a <a href="https://www.newtonsoft.com/json/help/html/SerializingJSON.htm" rel="nofollow noreferrer">link on the documentation</a></p>
  
  <p>So, why it is happening? How to convert this <code>&amp;quot;</code> to ordinary <code>"</code> for my case?</p>
  
  <h3>Update</h3>
  
  <p>I have tried this: </p>
  
  <pre><code>@section Scripts
  {
      &lt;script&gt;
          window.ManuallySending.advertiser_options = 
              JSON.parse(@Html.Raw(JsonConvert.SerializeObject(ViewBag.AdvertiserOptions)));
  
          window.ManuallySending.category_options = 
                      JSON.parse(@Html.Raw(JsonConvert.SerializeObject(ViewBag.CategorieOptions)));
  
      &lt;/script&gt;
  }
  </code></pre>
  
  <p>but it gives me new error: </p>
  
  <blockquote>
    <p>VM191:1 Uncaught SyntaxError: Unexpected token o in JSON at position 1
        at JSON.parse ()
        at Create:127</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/A7I9P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A7I9P.png" alt="enter image description here"></a></p>