請幫忙。剃鬚刀我頭痛。我正在嘗試使用谷歌圖表來顯示我的信息。剃鬚刀foreach循環和javascript
所以,這是我在我的觀點:
@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>
}
我使用foreach循環迭代模型上(IEnumerable<Tuple<DateTime,int>>
)在javascript函數添加的信息。在設計時,我得到
Conditional compilation is turned off
有沒有人知道如何解決這個問題?
感謝
編輯: 這是控制器:
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);
}
可能重複[條件編譯在剃刀關閉?(http://stackoverflow.com/questions/6655696/conditional-compilation-is-turned-off-in-razor) – wudzik