public
Last active

  • Download Gist
Chart.ascx
ASP
1 2 3 4 5 6
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<System.Web.UI.DataVisualization.Charting.Chart>" %>
<%
Model.Page = this.Page;
var writer = new HtmlTextWriter(Page.Response.Output);
Model.RenderControl(writer);
%>
ChartController.cs
C#
1 2 3 4 5 6 7 8 9
public class ChartController: Controller
{
public ActionResult MyChart()
{
var chart = new Chart();
// Configure chart
return View(chart);
}
}
MyChart.aspx
ASP
1
<% Html.RenderPartial("Chart", Model); %>
global.asax.cs
C#
1 2 3 4 5 6 7 8 9 10
protected void Application_Start()
{
// It's importat that this ignore of any url ending with ChartImg.axd is inserted before any Area route registrations.
// If you won't use Charts in any Area you can put it in your RegisterRoutes() method.
RouteTable.Routes.Ignore("{*pathInfo}", new { pathInfo = @"^.*(ChartImg.axd)$" });
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
 
// The rest..
}
web.config.xml
XML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<?xml version="1.0"?>
<configuration>
 
<!-- Your stuff -->
 
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;" />
</appSettings>
 
<!-- Your stuff -->
 
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<!-- Other assemblies -->
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>
 
<!-- Your stuff -->
 
<httpHandlers>
<!-- Other handlers -->
<add path="ChartImg.axd" verb="GET,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
</system.web>
 
<!-- Your stuff -->
 
</configuration>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.