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?

1
  • 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 }). Commented Apr 1, 2016 at 13:29

1 Answer 1

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" />
}
Sign up to request clarification or add additional context in comments.

2 Comments

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?
I think you need to use Url.Action. stackoverflow.com/questions/20165376/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.