【发布时间】:2018-07-14 15:30:52
【问题描述】:
我有一个函数在我的 MVC Web 应用程序的控制器中返回 json
public ActionResult GetWeeklyStats()
{
using (DBContext db = new DBContext())
{
var result = db.sp_StoredProcedureName.ToList();
return Json(result, JsonRequestBehavior.AllowGet);
}
}
返回的数据如下:
[
{
"WeekNo" : 1,
"Count" : 230
},
{
"WeekNo" : 2,
"Count" : 240
},
{
"WeekNo" : 3,
"Count" : 250
},
{
"WeekNo" : 4,
"Count" : 260
}
];
我正在尝试在我的视图中设置我的谷歌图表数据。这是我认为的ajax调用:
$.ajax({
type: "GET",
dataType: 'json',
contentType: 'application/json',
url: '@Url.Action("GetWeeklyStats", "myControllerName")',
async: false,
success: function (data) {
//set google data here ......
//how to do it here???
}
});
谷歌数据应该是这样的:
// Create the data table.
var gcData = new google.visualization.DataTable();
gcData.addColumn('number', 'WeekNo');
gcData.addColumn('number', 'Count');
gcData.addRows([
[1, 230],
[2, 240],
[3, 250],
[4, 260]
]);
【问题讨论】:
标签: json ajax linq model-view-controller google-visualization