Skip to content

Instantly share code, notes, and snippets.

@carlhoerberg
Created April 23, 2010 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlhoerberg/377126 to your computer and use it in GitHub Desktop.
Save carlhoerberg/377126 to your computer and use it in GitHub Desktop.
<%@ 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);
%>
public class ChartController: Controller
{
public ActionResult MyChart()
{
var chart = new Chart();
// Configure chart
return View(chart);
}
}
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..
}
<% Html.RenderPartial("Chart", Model); %>
<?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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment