2013-02-27 25 views
1

我目前正在MVC項目中工作,我目前的要求是在Aviary圖片編輯器中加載圖像。我遇到的問題是,我使用輸入類型「file」選擇的圖像使用FileContentResult呈現給視圖,並且我想要在aviary編輯器中加載此選定圖像。在Aviary編輯器中加載作爲FileContentResult返回的圖像

這使得在視圖中選擇圖像的圖像標籤是這樣的,

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

我會去啓動它在鳥舍圖像的ID和src,但截至這個FileContentResult返回作爲操作結果,它不會被加載到編輯器中;我不知道如何從中獲得真實的圖像。我怎樣才能在鳥舍中加載該圖片?

任何幫助都會很感激。

在此先感謝。

+0

任何一個請幫助! – Anu 2013-02-28 06:34:35

回答

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" />