MS Chart not rendering on MVC 2 with .NET 4
If you have been using ASP.NET 3.5 Charts, when upgrading to .NET 4 you will ran in to issues with the image source path for ChartImage.axd.
Make sure you add the following to your Global.asax.cs Application_Start.
RouteTable.Routes.Ignore(“{*pathInfo}”,new { pathInfo =@”^.*(ChartImg.axd)$” });
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
Note: the ignore route for ChartImage.axd needs to be before any area registration.
Web.Config Changes:
<assemblies>
<add assembly=“System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35“/>
</assemblies>
<controls>
<add tagPrefix=“asp“ namespace=“System.Web.UI.DataVisualization.Charting“ assembly=“System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35“ />
</controls>
<httpHandlers>
<add path=“ChartImg.axd“ verb=“GET,HEAD,POST“ type=“System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35“ validate=“false“/>
</httpHandlers>
<system.webServer>
<handlers>
<remove name=“ChartImageHandler“/>
<add name=“ChartImageHandler“ preCondition=“integratedMode“ verb=“GET,HEAD,POST“ path=“ChartImg.axd“ type=“System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35“/>
</handlers>
</system.webServer>
Thank you so much for this! I was trying to create a chart in a partial view by passing through a chart object as described in http://www.codecapers.com/post/Build-a-Dashboard-With-Microsoft-Chart-Controls.aspx and was getting very frustrated at getting an image not found symbol instead of the chart until I found your post.
I am glad that helped. I shared it because I also ran into the same problem once.