On the server, you need to serialize the data as JSON, and then you can write it in response as HTML, using something like a hidden input field.
For example, you can use the NewtonSoft JSON library to serialize JSON (which is built into ASP MVC 4 , however, it’s easy to install using Nuget)
string json = Newtonsoft.Json.JsonConvert.SerializeObject(images);
json HTML ( )
.
Response.Write(string.Concat("<input id='data' type='hidden' value='", json, "' />");
HiddenField jsonField = new HiddenField
{
ID = "data"
};
jsonField.Value = json;
this.Controls.Add(jsonField);
script, ( HTML, - Postbacks/Update, script)
Response.Write(string.Concat("<script type='text/javascript'> var images = ", json, ";</script>");
JSON HTML . polyfill - JSON2
.
var field = document.getElenentById('data');
var images = JSON.parse(field.value);
Javascript.