I am sending a string from JSON ASP.NET MVC, in my view I receive the JSON string and I assign a Script using ViewBag.string. My problem is in the view, the string type values are replacing the quotes with me & quot; which is causing me errors.
Controller:
var jss = new JavaScriptSerializer();
string retorno = jss.Serialize(chart.ToList());
ViewBag.datos = retorno;
ViewL
<script type="text/javascript">
new Morris.Bar({
element: 'BarChart',
data:@ViewBag.datos,
xkey: 'Planta',
ykeys: 'Cantidad',
labels: 'Mes'
})
</script>
This is the code that generates me to run the view
<script type="text/javascript">
new Morris.Bar({
element: 'BarChart',
data:`[{"Planta":"CO","Mes":3,"Cantidad":2},{"Planta":"EP","Mes":1,"Cantidad":1},{"Planta":"R1","Mes":1,"Cantidad":2},{"Planta":"RM","Mes":3,"Cantidad":3},{"Planta":"RQ","Mes":3,"Cantidad":1},{"Planta":"TY","Mes":1,"Cantidad":1},{"Planta":"TY","Mes":3,"Cantidad":3},{"Planta":"TY","Mes":4,"Cantidad":2},{"Planta":"ZB","Mes":3,"Cantidad":1},{"Planta":"ZB","Mes":4,"Cantidad":1}],`
xkey: 'Planta',
ykeys: 'Cantidad',
labels: 'Mes'
})
</script>