找不到资源.net mvc4

时间:2014-04-16 04:52:28

标签: asp.net-mvc highcharts

我尝试使用高图创建Web应用程序,这是我的教程http://csharptrenches.wordpress.com/2013/08/21/how-to-use-highcharts-js-with-asp-net-mvc-4/。我的控制器中的代码和视图没有一些错误。但是当我运行浏览器时我遇到了一些问题,它&# 39; s告诉我有关资源无法找到。你能告诉我为什么以及如何在这种情况下做。非常感谢你。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotNet.Highcharts;
using DotNet.Highcharts.Helpers;
using DotNet.Highcharts.Options;
using DotNet.Highcharts.Enums;

namespace HighCharts.Controllers
{

public class TransactionCount
{
    public string MonthName { get; set; }
    public int Count { get; set; }
}

public class IndexController : Controller
{
    //
    // GET: /Index/


    public ActionResult Index()
    {
      var  transaction = new List<TransactionCount> { 
                        new TransactionCount(){ MonthName="January", Count=40},
                        new TransactionCount(){ MonthName="February", Count=20},
                        new TransactionCount(){ MonthName="March", Count=35},
                        new TransactionCount(){ MonthName="April", Count=70}
                        };
        //change mountName & value to array
        var xDataMonths = transaction.Select(i => i.MonthName).ToArray();
        var yDataValue = transaction.Select(i => new object[] {i.Count}).ToArray();

        var chart = new Highcharts("chart")
            //choose type of graph
        .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column })
            //set a title
        .SetTitle(new Title { Text = "financial" })
            //sub title
        .SetSubtitle(new Subtitle { Text = "Accounting" })
            //load value to xAxis
        .SetXAxis(new XAxis { Categories = xDataMonths })
            //set the y title and format text
        .SetYAxis(new YAxis { Title = new YAxisTitle { Text = "Values" } })
        .SetTooltip(new Tooltip
        {
            Enabled = true,
            Formatter = @"function() { return '<b>'+ this.series.name +'</b><br />'+this.x +': '+ this.y:}"
        })
        .SetPlotOptions(new PlotOptions
        {
            Column = new PlotOptionsColumn
            {
                DataLabels = new PlotOptionsColumnDataLabels
                {
                    Enabled = true
                },
                EnableMouseTracking = false
            }
        })
            //load data value to yAxis
        .SetSeries(new[]{
                            new Series {Name = "Per Month", Data = new Data(yDataValue)}
        });

        return View(chart);

    }

}
}

这是我的观点

@{
ViewBag.Title = "Index";
}

<h2>Index</h2>
@model DotNet.Highcharts.Highcharts
<p>My Column Chart</p>
@(Model)

这是我的路线配置

using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace HighCharts
{
public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "IndexController", action = "ShowChart", id = UrlParameter.Optional }
        );
    }
}
}

1 个答案:

答案 0 :(得分:1)

问题出在路线配置

更改

defaults: new { controller = "IndexController", action = "ShowChart", id = UrlParameter.Optional });

defaults: new { controller = "Index", action = "Index", id = UrlParameter.Optional });

您的控制器没有您在代码中提供的名为ShowChart的操作,对于控制器参数,您只需要编写actionName。