我有一个简单的项目,它将ASP.NET MVC和ASP.NET Charts控件结合在一起。代码是非常简单的,如果我在VS 2008中运行它时没有指定任何“虚拟路径”,我就会在他的博客上跟随Mike Ceranski的帖子:http://www.codecapers.com/post/Build-a-Dashboard-With-Microsoft-Chart-Controls.aspx在虚拟路径中显示ASP.NET MVC站点中的ASP.NET图表控件
但是,如果我把虚拟路径项目属性中的“Web”选项卡),它将失败并产生此错误:无法映射路径'/ChartImg.axd'。所以它似乎仍然在调用ChartImg.axd在根目录中而不是在虚拟路径中。
所以,我的问题是 - 我如何才能让它进入虚拟路径呢?
我也已经完成了控制器的操作只是返回图像文件流 - 我不想 - 因为最终我希望能够使图表可点击而不是简单的图像。
这是我与ASP.NET图表web.config设置:
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;URL=/App_Data/MicrosoftChartControls/"/>
</appSettings>
<httpHandlers>
...
<add verb="*" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
代码控制器:
public ActionResult Index() {
ViewData["Message"] = "Welcome to ASP.NET MVC!";
ViewData["Chart"] = BindChartData();
return View();
}
private Chart BindChartData() {
Chart chart = new Chart();
chart.Width = 150;
chart.Height = 300;
chart.Attributes.Add("align", "left");
chart.Titles.Add("MY CHART");
chart.ChartAreas.Add(new ChartArea());
chart.Series.Add(new Series());
chart.Legends.Add(new Legend("MY CHART"));
chart.Legends[0].TableStyle = LegendTableStyle.Auto;
chart.Legends[0].Docking = Docking.Bottom;
for (int i = 0; i < 10; i++) {
string x = ChartTest.Models.Utility.RandomText();
decimal y = ChartTest.Models.Utility.RandomNumber(1, 100);
int ptIdx = chart.Series[0].Points.AddXY(x, y);
DataPoint pt = chart.Series[0].Points[ptIdx];
pt.LegendText = "#VALX: #VALY";
}
chart.Series[0].Legend = "MY CHART";
return chart;
}
代码为ASPX:
<%
supportChart.Controls.Add(ViewData["Chart"] as Chart);
%>
<asp:Panel ID="supportChart" runat="server"></asp:Panel>
已经做到了 - 就像我提到的,如果没有虚拟路径 - 它的作品,因为它应该。但添加虚拟路径会打破它。 – 2010-02-17 16:26:26