NickHeidke NickHeidke - 1 year ago 291
C# Question

Chart.Mvc colliding with System.Web.Helpers.Chart

I'm attempting to add Chart.Mvc controls (Chart.js) to my MVC 5 website. However, when I follow the example here:

I'm receiving the following error:

CS0426: The type name 'Mvc' does not exist in the type 'System.Web.Helpers.Chart'

It appears the reference I have to
is colliding with

I've tried it both with a fully qualified reference and without:

var barChart = new Chart.Mvc.ComplexChart.BarChart();
barChart.ComplexData.Labels.AddRange(new []{ "January", "February", "March", "April", "May", "June", "July"});
barChart.ComplexData.Datasets.AddRange(new List<ComplexDataset>...


var barChart = new BarChart();
barChart.ComplexData.Labels.AddRange(new []{ "January", "February", "March", "April", "May", "June", "July"});
barChart.ComplexData.Datasets.AddRange(new List<ComplexDataset>

This second option does throw a slightly different error:

CS0246: The type or namespace name 'BarChart' could not be found (are you missing a using directive or an assembly reference?)

using Chart.Mvc;
to the Controller or
to the View does not help;

Answer Source

Ran into the same issue myself, and found the answer when poking through the Github repo. You need to add the namespaces to Chart.Mvc in the /Views/web.config file.

See the author's /Views/web.config file for reference.

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Optimization"/>
    <add namespace="System.Web.Routing" />
    <add namespace="Chart.Mvc.Sample" />
    <add namespace="Chart.Mvc" />
    <add namespace="Chart.Mvc.ComplexChart" />
    <add namespace="Chart.Mvc.SimpleChart" />
    <add namespace="Chart.Mvc.Sample.Models" />
    <add namespace="Chart.Mvc.Extensions"/>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download