I would like to access a List<Records> where Records is a struct, from a JS script. After a bit of googling (especially question 29098558 here) i Json serialized my object and retrieve it in the script.
I should mention it's my first time at JS so syntax may be totally wrong.
In C#
string serializedResults = JsonConvert.SerializeObject(RecordsList);
(in my context the records are actually in a Dictionnary<string, Records> but i hide the access through dictionnary because i supposed it isn't relevant here)
In Javascript
<script type="text/javascript">
function setupBarChart() {
var x = [];
var y = [];
var source = "<%= serializedRecords %>";
// I would like to put Records fields in y and x tab to use it as data for the axes of an histogram.
for (var i = 0; i < source.length; i++) {
}
}
</script>
My questions are :
- what is the type of source ? Is it just a string ? Does it create an equivalent of List in JS ?
- How do I access my Records fields from JS ?
- Does source.length gives me the number of records in the list ??
JsonConvert.SerializeObject? You have declaredserializedResultsbut you are trying to useserializedRecords. Looks like some typo.