0

I have been working with charts today And I think that i finaly found a way for it all to work but I encountered an issue that I don't know how to pass.

Create my Charts in my controller:

    foreach (var m in model[0].HistoryValues)
    {

        var chart = new Chart(width: 300, height: 200)
        .AddSeries(
        chartType: "bar",
        xValue: new[] { "Server", "Db", "Tickets" },
        yValues: new[] { m.ServerPerformance, m.Databaseperformance, m.SoldTicketsLastUpdate })
        .GetBytes("png");

        m.Bytes = chart;

        //m.ChartFile = File(chart, "image/bytes");
    };

now I want to display them as Images in the view:

   @foreach (var m in Model[0].HistoryValues)
    {
        <img src="@Html.Action("getImage", "OverWatch", new { byte[] Mybytes= m.Bytes })" alt="Person Image" />
    }

but im getting:

Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

getImage method:

public FileContentResult getImage(byte[] bytes)
{
   return new FileContentResult(bytes, "image/jpeg");
}

How do I solve this?

ThunD3eR
  • 2,815
  • 5
  • 38
  • 73
  • 1
    The problem you're facing states that you souldn't declare the type on an anonymous type. Write like this: `new { Mybytes = m.Bytes })`. – Vitor Rigoni Apr 01 '16 at 13:29

1 Answers1

1

In an anonymous type you dont define the variable type byte[]. It works it out itself based on the type of m.Bytes

@foreach (var m in Model[0].HistoryValues)
{
    <img src="@Html.Action("getImage", "OverWatch", new { Mybytes= m.Bytes })" alt="Person Image" />
}
CathalMF
  • 8,557
  • 4
  • 55
  • 84
  • This was the answer to the question. Thank you!. Although somethign else came up right now and I figure since I have your attention. The end result was still not what i was hoping for. the src in the browser is: "System.Web.Mvc.FileContentResult" Any ideas? – ThunD3eR Apr 01 '16 at 13:41
  • I think you need to use Url.Action. http://stackoverflow.com/questions/20165376/asp-net-mvc-image-from-byte-array – CathalMF Apr 01 '16 at 13:52