1

I am currently working in an MVC project and my current requirement is to load an image in Aviary picture editor. The problem occurred to me is that, the image I selected using input type "file" is rendered to the view using FileContentResult, and I want to load this selected image in Aviary editor.

The image tag which renders the selected image on the view is something like this,

<img id="imgTest" src="<%: Url.Content("~/[Controller]/[Action]/?a=" + Model.a + "&b=" + Model.b + "&c=" + Model.c) %>" alt="example" />

I will get the id and src of the image to launch it in aviary, but as this this a FileContentResult returning as the action result, it will not get loaded in the editor, and I am not sure how to get the real image from this. How can I load that image in Aviary?

halfer
  • 19,824
  • 17
  • 99
  • 186
Anu
  • 127
  • 3
  • 12

1 Answers1

3

You can define an action that return FileContentResult like:

public FileContentResult getImage(int id)
{
    byte[] byteArray = DbContext.Persons.Find(id).Image;
    if (byteArray != null)
    {
        return new FileContentResult(byteArray, "image/jpeg");
    }
    else
    {
        return null;
    }
}

In Razor

<img src="@Html.Action("getImage", "Person", new { id = item.Id })" alt="Person Image" />
M.Azad
  • 3,673
  • 8
  • 47
  • 77