1👍
If it is an C# Array in the ViewBag:
var outcomeData = @Html.Raw(Json.Encode(@ViewBag.ChartOutput));
use Json.Encode
and Html.Raw
Usefull Links:
- Check this for more information:
MVC: Iterating a Viewbag array in javascript - Or this for a 2D array if thats important for you: Pass 2D
array from Controller Viewbag to JS
If it is a String in the Viewbag:
You can use the value from the ViewBag in JS like this:
var outcomeData = '@ViewBag.ChartOutput';
then you dont need the Html.Raw
- Chartjs-Adding responsive text inside chart in Charts Js
- Chartjs-Loop through array of objects in Node
Source:stackexchange.com