2011-10-21 86 views
0

我需要顯示數據庫中的圖像。 在控制器:從數據庫中顯示圖像

public ActionResult Display(int id, Document doc) 
{ 
    byte[] byteArray = doc.Content;//its has the image in bytes 
    return new FileStreamResult(new System.IO.MemoryStream(byteArray), "image/jpeg"); 
} 

在View:

@foreach (var imgsrc in Model.ImagesSrc) 
{ 
    <img src="@Url.Action("Display", "image", new { id = @imgsrc.Id })" alt="" /> 
} 

它不工作

+0

「這不工作」不足以描述發生的情況。請閱讀http://tinyurl.com/so-hints –

+0

在輸出它顯示帶問號的圖像 – user930453

+0

所以你試圖下載正在服務的文件?用Wireshark看網絡流量?你試過什麼樣的診斷? –

回答

0

你的控制器方法需要另外一種Document doc但您的網址是唯一確定的ID。您應該使用ID爲

public ActionResult Display(int id) 
{ 
    Document doc = GetDocById(id); 
    byte[] byteArray = doc.Content;//its has the image in bytes 
    return new FileStreamResult(new System.IO.MemoryStream(byteArray), "image/jpeg"); 
}