イメージをデータベースに保存し、MVC を使用して取得して表示する方法
MVC3、Entity Framework Database First、および SQL SERVER 2008 を使用しています
データベースでは、画像に varbinary(MAX) を使用しました
Image varbinary(MAX) Checked
さらに私が使用した
[DisplayName("Image")]
public byte[] Image { get; set; }
私のマッピングクラスで
Createアクションメソッドで保存しようとしたとき
public ActionResult Create(MarjaaModel newMarjaa, HttpPostedFileBase uploadFile)
{
if (uploadFile != null && uploadFile.ContentLength > 0)
{
newMarjaa.Image = new byte[uploadFile.ContentLength];
uploadFile.InputStream.Read(newMarjaa.Image, 0, uploadFile.ContentLength);
}
try
{
data.submitMarjaa(newMarjaa);
return RedirectToAction("Index");
}
catch
{
return View();
}
}
画像をバイナリデータとして保存することに成功しています
しかし、この画像を取得してビューに表示する方法を教えてください