title: using viewbag data with jquery json
body: <p>I want to use my <strong>ViewBag</strong> in JavaScript array. I follow <a href="https://stackoverflow.com/questions/7905193/using-viewbag-with-jquery-asp-net-mvc-3">using viewbag with jquery asp.net mvc 3</a>, and I think the following code is what I am looking for,</p>
  
  <pre><code> @model MyViewModel
  
  &lt;script type="text/javascript"&gt;
     var model = @Html.Raw(Json.Encode(Model));
      // at this stage model is a javascript variable containing
      // your server side view model so you could manipulate it as you wish
     if(model.IsLocal)
     {
         alert("hello " + model.FirstName);
     }
  &lt;/script&gt;
  </code></pre>
  
  <p>But this code causes error for <code>Json.Encode</code>, then I add <code>System.Runtime.Serialization.Json</code>, but It also cause error for <code>Encode</code>, says no method for <code>Encode</code>, I already include <code>Newtonsoft.Json</code>, but still no result.</p>
  
  <p>My ViewBag data ::</p>
  
  <pre><code> public ActionResult Dashboard() 
   {
      ViewBag.inc = (from inc in db.Incident select inc.Title).ToList();
      return View();
   }
  </code></pre>
  
  <p>And I want to use this <code>ViewBag.inc</code> data in <strong>JavaScript array</strong>  </p>