Please help. I am getting a headache with razor. I am trying to use google charts to display my information.
So, this is what I have in my view:
@section scripts
{
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Date', 'DDM'],
@foreach(var item in Model.ToList())
{
<text>
['item.Item1', 'item.Item2']
</text>
}
]);
var options = {
title: 'Demande de marché',
hAxis: { title: 'Date', titleTextStyle: { color: '#333'} }
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
}
I use the foreach loop to iterate on the model (IEnumerable<Tuple<DateTime,int>>) to add the information in the javascript function. At design time, I get
Conditional compilation is turned off
Does anyone know how to solve this?
Thanks
Edit: This is the controller:
public ActionResult DDMPerDepartment(string department)
{
if (DepartmentsList == null) DepartmentsList = _db.Departments.ToList();
ViewBag.DepartmentString = DepartmentsList.First().DepartmentName;
IEnumerable<Tuple<DateTime,int>> points = _db.DepartmentNumbers.Where(x => x.Department.Id == 1).Select(x => new Tuple<DateTime, int>(x.Date, x.Number));
return View(points);
}