I have a C# List<String>
, and I need to convert it to a JavaScript
list of strings.
I'm currently stuck at:
System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); test = oSerializer.Serialize(tempString);
In JavaScript
, I can get it like this (test is a protected string variable)
var servervalue = '<%=test %>';
In the console I get
var servervalue = '["100000001","200000002","200000003","300000006","300000007"]';
and I need to get it without the single quotation marks, like this:
["100000001", "200000002", "200000003", "300000006", "300000007"];
Newtsonsoft.Json
, Microsoft actually recommends it over the built in serializer. Also, you could simply use a global or Session and assign the value, depending on your implementation. Not sure your goal.