You need to convert your C# array into a valid javascript Array (i.e. ["a","b","c"...]
). There are many ways to do that here is my suggestion:
string.Concat("[", string.Join(",", Model.DatasetTitles.Select(s => string.Concat("'", s, "'"))), "]");
In essence I am taking each element in the DatasetTitles
collection and transforming it to a javascript string literal. Then joining those all up with ,
separators and finally putting square brackets around the whole thing.
Not particularly elegant and there are almost certainly better ways to transform the data but hopefully that will get you on the right track.
EDIT: You could also look at the JavaScriptSerializer
which is the frameworks class for converting C# objects to valid javascript. This is probably perferrable over manually transforming the data as shown above. See this answer for an example: https://stackoverflow.com/a/9024029/61470