title: Using ViewData in Javascript code
body: <p>I'm creating a ViewData in an ASP.Net Controller like this:</p>
  
  <pre><code>var elements = db.Requests.GroupBy(user =&gt; user.submitUser)
                     .Select(slt =&gt; new { UsersCount = slt.Key, CountReq = slt.Count() });
  </code></pre>
  
  <p>this will have for example</p>
  
  <pre><code>UsersCount      Count
  
  user1           3
  
  user2           3
  
  user3           3
  </code></pre>
  
  <p>Then in Javascript I want to create an array with UsersCount and Count, for example:</p>
  
  <pre><code>var arrayUsers = ViewData.UsersCount;
  var arrayCounter = ViewData.CountReq;
  </code></pre>
  
  <p>I already tried several solutions and I can't do it. What's the best solution?</p>
  
  <p>CONTROLLER:</p>
  
  <pre><code> public ActionResult Statistics()
          {
              var elements = db.Requests.GroupBy(user =&gt; user.submitUser)
                              .Select(slt =&gt; new { UsersCount = slt.Key, CountReq = slt.Count() });
  
  
              ViewData["usersCounter"] = elements;
  
              return View();
          }
  </code></pre>
  
  <p>Javascript in VIEW</p>
  
  <pre><code>&lt;script&gt;
      var check = @ViewData["usersCounter"]**;**error
  
  ....
  
  }
  </code></pre>