0

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

2
  • 1
    use something like NewtonSoft JSON to serialize the object and print to the page Commented May 15, 2017 at 20:14
  • Possible duplicate of Pass Array from MVC to javascript? Commented May 15, 2017 at 20:19

1 Answer 1

0

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"];

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.