在asp.net mvc3中图表助手没有显示母版页

时间:2012-12-10 12:04:05

标签: asp.net-mvc-3 charts

我正在尝试在ASP.NET MVC3中使用Chart Helper。但我面临的问题是,只显示相关图表而没有母版页。

我的代码是:

控制器

     public ActionResult Chart()
            {
                Chart chart = new Chart(width: 600, height: 400)
                       .AddTitle("Chart")
                    .AddSeries(
                    chartType: "line",
                    legend: "Rainfall",
                    xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May" },
                    yValues: new[] { "20", "20", "40", "10", "10" }).AddSeries(chartType: "line", yValues: new[] { "30", "40", "50", "60", "70" }).Write("png");

                return null;

            }

查看

@model dynamic
@{
    ViewBag.Title = "Chart";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Chart</h2>
<h2>About</h2>
<p><img src="@Url.Action("Chart")" alt="hello chart" /></p>

请帮我找到我错的地方。

先谢谢

1 个答案:

答案 0 :(得分:1)

您需要将图表作为图像返回。试试这个:

 public ActionResult Chart()
        {
            Chart chart = new Chart(width: 600, height: 400)
                   .AddTitle("Chart")
                .AddSeries(
                chartType: "line",
                legend: "Rainfall",
                xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May" },
                yValues: new[] { "20", "20", "40", "10", "10" }).AddSeries(chartType: "line", yValues: new[] { "30", "40", "50", "60", "70" })
        .GetBytes("png");


            return File(chart, "image/png");

        }