2011-10-21 17 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"); 
} 

:それは

+0

"動作していません"は何が起こっているのかについての十分な説明ではありません。 http://tinyurl.com/so-hints –

+0

を読んでください。出力には疑問符 – user930453

+0

の画像が表示されます。提供されているファイルをダウンロードしようとしましたか? Wiresharkとのネットワークトラフィックを見ていますか?どのような種類の診断を試みましたか? –

答えて

0

お使いのコントローラメソッドを動作していない

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

Document docを期待しているが、あなたのURLは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"); 
} 
関連する問題