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:
<input type="hidden" id="tutors" name="tutors" value="<%: PeerTutoring.StaticData.GetTutorsSerialized()%>" />
The method GetTutorsSerialized is:
public static string GetTutorsSerialized()
{
char[] stuff = new JavaScriptSerializer().Serialize(new PeerTutoring.Models.PeerTutoringDataContext().Tutors).ToArray();
return stuff.ToString();
}
Next, I have tried accessing this information from Javascript like this:
var x = $('#tutors').val()
alert(x);
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[]".
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? :
x[0].Email
Thanks for the help.