【问题标题】:Load an image returned as a FileContentResult in Aviary Editor在 Aviary 编辑器中加载作为 FileContentResult 返回的图像
【发布时间】:2013-02-12 21:54:03
【问题描述】:

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

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

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

我将获取图像的 id 和 src 以在 aviary 中启动它,但由于这是作为操作结果返回的 FileContentResult,它不会在编辑器中加载,我不知道如何获得真实的从这个图像。如何在 Aviary 中加载该图像?

【问题讨论】:

    标签: asp.net-mvc aviary filecontentresult


    【解决方案1】:

    您可以定义一个返回 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" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 2013-08-15
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      相关资源
      最近更新 更多