问题
I need to pass a list (or array) of IP addresses and other information from C# code behind to the javascript function, which is in the external .js..
Also, this list may be long (1000+ items) .. What is the most efficient way to do this? can you provide a small example? should I use json serialization?
回答1:
var myObject = <%= JustSerializeAsJson(...) %>;
... or pass it to a function to whatever. Point is JSON is a valid JavaScript literal so you can drop it in a number of places. Don't worry about "efficiency" here unless there is a profiled problem. Both the generation and JavaScript parsing should be really fast. (Bing maps loads like 1MB file in JS!)
MSDN JSON Serializer
来源:https://stackoverflow.com/questions/4799551/pass-array-or-tlist-from-c-sharp-code-behind-to-external-javascript