jquery - Push List<string> into dictionary value in javascript -
i want push list of type string value dictionary in js script. js dictionary should contain key datetime, , list value.
@foreach (keyvaluepair<datetime, list<string>> item in model.assignedattractions) { <script type="text/javascript"> var dictionary = []; $(function () { dictionary.push({ key: @item.key.toshortdatestring(), value: @item.value.toarray(), }); }); </script> }
presented solution value: @item.value.toarray()
is not working.
add @using newtonsoft.json
view
. , then,
dictionary.push({ key: @item.key.toshortdatestring(), value: @html.raw(jsonconvert.serializeobject(item.value)), });
jsonconvert.serializeobject
converts c# object json string
you avoid loop this:
@html.raw(jsonconvert.serializeobject(model.assignedattractions.select(a => new { key = a.key.toshortdatestring(), value = a.value })));
Comments
Post a Comment