title: Combine MVC .NET Razor with Javascript to build an array
body: <p>I'm passing a List from my controller to a view, where I want to be able to take the Model and loop through results in JQuery/Javascript. I'm having a heck of a time figuring out how to do that.</p>
  
  <p>My controller returns a list of colors. In the view, I converted the List to an array. I then pass it to my  where I'm trying to loop through it to build an array I can using in my JS.</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function () {
  
      var currentView = sessionStorage.getItem('lastView');
      var jsArr;
      for (i=0; i&lt;@arr.Length; i++) {
          jsArr.push(@arr[i])
      }
  
      if (!currentView) {
          sessionStorage.setItem('lastView', 0);
          $("body").css("background-image", "url('/Images/Home/@arr[0].Location')");
      } else {
  
          sessionStorage.setItem('lastView', currentView++);
      }
  })
  &lt;/script&gt;
  </code></pre>
  
  <p>There has to be an easy way of doing this...</p>