0

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

我的代码是:

控制器

     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>

请帮我找出我哪里出错了。

提前致谢

4

1 回答 1

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");

        }
于 2012-12-10T12:15:05.633 回答