title: ASP.NET MVC 4 - Dynamically Creating Table Using Javascript and C# Array Data
body: <p>For my project, I would like to dynamically display a table containing information from my database. Unfortunately, I am unable to pass the c# array containing all of my database's information into a Javascript array. I have tried creating a hidden field like this:</p>
  
  <pre><code>&lt;input type="hidden" id="tutors" name="tutors" value="&lt;%: PeerTutoring.StaticData.GetTutorsSerialized()%&gt;" /&gt;
  </code></pre>
  
  <p>The method GetTutorsSerialized is:</p>
  
  <pre><code>public static string GetTutorsSerialized()
      {
          char[] stuff = new JavaScriptSerializer().Serialize(new PeerTutoring.Models.PeerTutoringDataContext().Tutors).ToArray();
          return stuff.ToString();
      }
  </code></pre>
  
  <p>Next, I have tried accessing this information from Javascript like this:</p>
  
  <pre><code>var x = $('#tutors').val()
          alert(x);
  </code></pre>
  
  <p>This displays the message "System.Char[]" in the alert box. The length of the 'x' is also 13, which is the length of the string "System.Char[]".</p>
  
  <p>Also, once I have got this array working, will I be able to access fields of the object's held in the Javascript array like this? :</p>
  
  <pre><code>x[0].Email
  </code></pre>
  
  <p>Thanks for the help.</p>