OutputStream is not available if custom TextWriter is used by mvc

I am trying to get a chart in my view and I will show it as follows:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>ChartResult</h2> <% using (Html.BeginForm("HandleChartType", "Chart")) %> <% { %> <%= Html.DropDownList("ListItems", "Select Chart Type")%> <input type="submit" value="Set Chart" /> <%} %> <% myChart.Controls.Add(ViewData["Chart"] as Chart); %> <asp:Panel ID="myChart" runat="server"></asp:Panel> <!--<img src="/Chart/CreateChart" alt="" />--> <h2>FormResults</h2> </asp:Content> 

This line is <% myChart.Controls.Add (ViewData ["Chart"] in the form of a diagram); %> generates an error message. OutputStream not available if custom TextWriter is used

This is the controller code:

  public ActionResult ChartResult() { List<string> items = GetFilteredChartTypes(); ViewData["ListItems"] = new SelectList(items); Chart myChart = CreateChart(SeriesChartType.Column); ViewData["Chart"] = myChart; return View(); } 

The CreateChart function simply creates a chart with a chart type in the form of a column. Why am I getting this error, OutputStream is not available if a custom TextWriter is used?

+7
source share
1 answer

I think the problem is the wrong approach. When creating charts, you have two options.

One way is to create an image diagram, and then your presentation will consist of a <img /> with the src attribute set to the URL of the controller / action that generates the diagram image.

Another way is to create a controller with a JSON action that returns only data only . This is a more flexible way, because you get the freedom to choose any of the ready-made javascript libraries that render graphics (html5 canvas or svg)

0
source

All Articles