Pass Array from MVC to javascript?

You could let .NET handle all the heavy lifting for you with this simple line of code.

This assumes you’re using MVC Razor syntax.

var yourJavaScriptArray = @Html.Raw(Json.Encode(Model.YourDotNetArray));

For newer versions of MVC, use:

var yourJavaScriptArray = @Html.Raw(Json.Serialize(Model.YourDotNetArray));

Leave a Comment