title: Passing an array from Controller to View
body: <p>I am trying to do what seems like the simplest thing in the world, but it has me absolutely banging my head against the wall in frustration. I just need to pass a simple string array from a C# method in my Controller class to javascript code in my index view. That's it. Just pass a simple array. But damned if I can figure out how, or make any sense of any of the convoluted answers I've seen on the internet.</p>
  
  <p>Here are the details (simplified):</p>
  
  <p>My controller:</p>
  
  <pre><code>public class BobsController : Controller
  {
      // GET: Bobs
      public ActionResult Index()
      {
          return View();
      }
  
      public ActionResult ReturnBobsStuff()
      {
      List&lt;string&gt; myList = new List&lt;string&gt; { "element1", "element2", 
                                               "element3", "element4", 
                                               "element5", 
                                             };
      string[] myArray = myList.ToArray();
      return View(myArray);
      }
   }
  </code></pre>
  
  <p>My view:</p>
  
  <pre><code>&lt;script&gt;
      $(function () {
              var JavascriptArray = ??;
            });
  &lt;/script&gt;
  </code></pre>
  
  <p>The ?? is the problem, obviously.</p>