在Aviary Editor中加载作为FileContentResult返回的图像

时间:2013-02-27 07:14:33

标签: asp.net-mvc aviary filecontentresult

我目前正在从事MVC项目,目前的要求是在Aviary图片编辑器中加载图片。我遇到的问题是,我使用输入类型“文件”选择的图像使用FileContentResult渲染到视图,我想在鸟舍编辑器中加载这个选定的图像。

在视图上呈现所选图像的图像标记就是这样的,

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

我将获得图像的id和src以在鸟舍中启动它,但是这样一个FileContentResult作为动作结果返回,它将不会被加载到编辑器中;而且我不确定如何从中获得真实的图像。如何在鸟舍中加载该图像?

任何帮助都会非常感激。

先谢谢。

1 个答案:

答案 0 :(得分:3)

您可以定义一个返回 FileContentResult 的操作,如:

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

在剃刀中

<img src="@Html.Action("getImage", "Person", new { id = item.Id })" alt="Person Image" />
相关问题