How not works mix code JS in a Razor View

Viewed 21

I try to use in a View a JS function and mix with a Razor Code, but for any reason after the code marked FROM HERE not continues the execution of function, something missing to the function to continue after included the Razor code?

<script type="text/javascript">
        FusionCharts.ready(function () {
            var data2 = [];

         @for (var i = 0; i < totalt; i++)
         {
                @:data2.push({
                    @:label: "@data.Results[i].Timestamp",
                    @:value: "@data.Results[i].Value",
                });
**FROM HERE**
            var chartObj = new FusionCharts({
                type: 'line',
                renderAt: 'chart-containeriot',
                width: '493',
                height: '300',
                dataFormat: 'json',
                dataSource: {
                    "chart": {
                        "showBorder": "0",
                        "showShadow": "0",
                        "use3DLighting": "0",
                        "showLabels": "0",
                        "showValues": "1",
                        "paletteColors": "#58E2C2, #F7E53B",
                        "bgColor": "#191c51",
                        "bgAlpha": "100",
                        "canvasBgAlpha": "0",
                        "decimals": "0",
                        "baseFont": "Arial",
                        "baseFontColor": "#FFFFFF",
                        "canvasTopMargin": "0",
                        "showTickMarks": "0",
                        "showTickValues": "0",
                        "showLimits": "0",
                        "majorTMAlpha": "0",
                        "minorTMAlpha": "0",
                        "pivotFillAlpha": "0",
                        "showPivotBorder": "0",
                        "xAxisName": "Day",
                        "yAxisName": "Metros Cubicos",
                        "lineThickness": "2"
                    },
                    "data": data2
                }
            });
            chartObj.render();
        });
    </script>
1 Answers

Razor interprets @ as razor syntax. You should escape your code with @@

@@:data2.push({
   @@:label: "@data.Results[i].Timestamp",
   @@:value: "@data.Results[i].Value",
});
Related