Reputation: 281
Currently, I have this code for copy data from my array in C# Model to javascript array.
var javascriptArray = [];
@foreach (var data in Model.Array)
{
@:javascriptArray.push(@Html.Raw(data));
}
but in result html I have many times
javasriptArray.push("string1");
javasriptArray.push("string2");
javasriptArray.push("string3");
...
Is there any other way to do this?
thx
Upvotes: 0
Views: 1315
Reputation: 252
You can try serializate the Array object (Newtonsoft.Json), example:
JsonConvert.SerializeObject(Model.Array);
Or you can print a var array in javascript:
var myArray = ["AA","BB","CC"];
Upvotes: 0