Let's say I have a class called ApplicationSettingsManager, and I have a String that needs referencing from Javascript on my ASP .net page, I have done the following:
<%=ApplicationSettingsManager.IdNumber %>
And it works fine. But what if I need to reference a Dictionary<String,String>
? Or any other slightly more complex type? Is it possible? Do I need to use serialization somehow?
Yes, it is recommended to use JSON serialization when passing complex types to javascript. For example you could use the JavaScriptSerializer class:
Example with a
Dictionary<string, string>
:which will render as:
in the final markup.