The problem is that arrTickerCountents.ToString() does not return the expected results.
For example, (new [] {"hello", "world"}).ToString() evaluates to "System.String[]" , which is not useful here.
A valid way to handle this is to use a converter, which can emit a valid JavaScript value from a suitable .NET object - the most common tool is probably a JSON converter. I like Json.NET , but this should work with other converters.
var jsonArray = JsonConvert.SerializeObject(arrTickerContents); script.InnerHtml = @" var rss_scr_contents = []; $.each(" + jsonArray + @", function (i, objValue) { rss_scr_contents[i] = objValue; }) ";
Since the above loop does not process, it considers a simpler alternative. (I prefer not to use var with global window properties.)
script.InnerHtml = @"rss_scr_contents = " + jsonArray + ";";
I recommend JSON for its simplicity and automatic transformations available, although this may not always apply. Manually building a JavaScript value (i.e., without the JSON library) should be done with caution, since it is fairly easy to enter incorrect, malicious, or other unexpected output.
user166390
source share