c# - ASP NET MVC array in controller to client side array -


my question how ( if possible ) array string[] a; pass view through viewbag, how can obtain javascript array of strings.

i want use because set of data db , want in view make chart , need javascript array.

it's easy "render" array javascript object, using string.join or similar:

@{     viewbag.a = new int[] { 1, 2, 3 };     viewbag.b = new string[] { "a", "b", }; }  <script type='text/javascript'>     // number array     var = [ @(string.join(", ", (int[])viewbag.a)) ];     console.log(a);  // [1, 2, 3]      // string array -- use html.raw     var b = [@html.raw("'" + string.join("', '", (string[])viewbag.b) + "'")];     console.log(b); </script> 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -