T
T
Towue2019-11-10 17:09:07
JavaScript
Towue, 2019-11-10 17:09:07

how to pass array from c# to javascript?

how to pass array from c# to javascript?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eRKa, 2019-11-10
@kttotto

Judging by the tag, you want to do this in an ASP MVC application.
There is an option to do this on a view using Razor

<script>
  var model = @Json.Serialize(Model.yourArray);
  
  var model2 = @Html.Raw(JsonConvert.SerializeObject(Model.yourArray));
  
  var model3 = [@Model.yourArray[0], @Model.yourArray[1], @Model.yourArray[2]]
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question