2012-12-10 41 views
0

我想在ASP.NET MVC3中使用圖表助手。但我面臨的問題是,只有關心的圖表顯示沒有母版頁。在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> 

請幫我找到我要去的地方錯了。

在前提前感謝

回答

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

     } 
+0

我試圖通過在URL操作值如@ Url.Action(「圖表」,新{ID = ViewBag.Value}),但它不工作,而不是重定向我這個圖表值。請幫助如何做到這一點 – Aada

+0

您是否已將ID參數添加到'Chart()'方法? '公衆的ActionResult圖表(INT ID)' – levelnis

+0

@levelnis它說:「不能隱式轉換字節[]圖表」。 – Igor