我正在创建一个由几个Telerik UI for ASP.NET MVC Charts组成的仪表板。第一张图应该是针对给定代理逐月绘制销售量。我的控制器类如下:
static List<SalesAgentViewModel> SalesAgentData = new List<SalesAgentViewModel>(){
new SalesAgentViewModel
{
SalesAgentID = 1,
ChartData = new List<SalesAgentChartItem>()
{
new SalesAgentChartItem
{
MonthName="January",
MerchantMCVolume=25000,
MerchantVisaVolume=500000
},
new SalesAgentChartItem
{
MonthName="February",
MerchantMCVolume = 225000,
MerchantVisaVolume = 725000
},
new SalesAgentChartItem
{
MonthName="March",
MerchantMCVolume = 75000,
MerchantVisaVolume = 150250
}
}
},
new SalesAgentViewModel
{
SalesAgentID = 2,
ChartData = new List<SalesAgentChartItem>()
{
new SalesAgentChartItem
{
MonthName="January",
MerchantMCVolume = 98000,
MerchantVisaVolume = 75250
},
new SalesAgentChartItem
{
MonthName = "February",
MerchantMCVolume = 87500,
MerchantVisaVolume = 68250
},
new SalesAgentChartItem
{
MonthName = "March",
MerchantMCVolume = 68500,
MerchantVisaVolume = 78125
}
}
}
};
[Authorize(Roles ="Admin,SalesAgent")]
public ActionResult ReadSalesAgentData([DataSourceRequest]DataSourceRequest request)
{
return Json(SalesAgentData.ToDataSourceResult(request));
}
[Authorize(Roles ="Admin,SalesAgent")]
public ActionResult ReadGraphData(int id)
{
return Json(SalesAgentData.First(v => v.SalesAgentID == id).ChartData);
}
然后,我在视图中新建了一个图表,如下所示:
<div class="container" id="dashboard">
@(Html.Kendo().Chart<SalesAgentChartItem>()
.Name("SalesAgentVolume")
.Title("Sales Agent Volume")
.DataSource(dataSource => dataSource
.Read(read => read.Action("ReadGraphData","SalesAgents"))
)
.Series(series=>
{
series.Line(s => s.MerchantMCVolume).CategoryField("Mastercard Volume");
series.Line(s => s.MerchantVisaVolume).CategoryField("Visa Volume");
})
.CategoryAxis(axis=>axis
.Categories(model=>model.MonthName))
)
</div>
当我运行应用程序时,会呈现图形,但会抛出一个HTTP 500:
System.ArgumentException: The parameters dictionary contains a null entry
for parameter 'id' of non-nullable type 'System.Int32' for method
'System.Web.Mvc.ActionResult ReadGraphData(Int32)' in
'Web.Controllers.SalesAgentsController'. An optional parameter must be a
reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
我的目的是显示SalesAgentID标识的给定代理的卷。我该如何做到这一点?