我刚刚升级到 .NET 4,我的 ASP.NET 图表控件不再显示。
对于 .NET 3.5,控件生成的 HTML 过去看起来像这样:
<img id="20_Chart" src="/ChartImg.axd?i=chart_5f6a8fd179a246a5a0f4f44fcd7d5e03_0.png&g=16eb7881335e47dcba16fdfd8339ba1a" alt="" style="height:300px;width:300px;border-width:0px;" />
现在,对于 .NET 4,它看起来像这样(注意源路径中的更改):
<img id="20_Chart" src="/Statistics/Summary/ChartImg.axd?i=chart_5f6a8fd179a246a5a0f4f44fcd7d5e03_0.png&g=16eb7881335e47dcba16fdfd8339ba1a" alt="" style="height:300px;width:300px;border-width:0px;" />
图表位于 MVC 部分 View 中,该 View 位于名为“Statistics”的 MVC Area 文件夹和名为“Summary”的 MVC Views 文件夹中(即“/Areas/Statistics/Views/Summary”),因此这显然是其中的位置路径的改变来自于。
我所做的只是将 System.Web.DataVisualization 程序集从 3.5 切换到 4.0。
非常感谢任何帮助。
最佳答案
虽然@Michael 的解决方案提供了有关此问题存在原因的信息,但还有一个更简单的解决方案。在 global.asax.cs 中的 Controller 句柄中注册路由时,您可以添加带有约束的忽略路由,如下所示:
protected void Application_Start() {
...
RouteTable.Routes.Ignore("{*pathInfo}", new { pathInfo = @"^.*(ChartImg.axd)$" });
...
}
关于ASP.NET 图表控件不再适用于 .NET 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2631526/