Pass array (or TList) from C# code behind to external javascript?

柔情痞子 提交于 2019-12-12 01:34:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!