0
私はFYPで働いている最終学年の学生です。データベースにバイナリデータで保存されているイメージを取得することに問題があります。私はたくさんの解決策を試しましたが、私はGoogleで検索しましたが、解決策はありません。MVCのリストに画像を表示する方法は?
表示
@model IEnumerable<PictureServices.Picture>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
<tr>
@foreach (var item in Model)
{
<td>
@{
var base64 = Convert.ToBase64String(item.image);
var imgsrc = string.Format("data:image/jpg;base64,{0}", base64);
}
<img src='@imgsrc' style="max-width:100px; max-height:100px;">
</td>
モデル
public class Picture
{
public int id { get; set; }
public byte[] image { get; set; }
public string name { get; set; }
}
コントローラ
public class CarServicesController : Controller
{
TestingEntities db = new TestingEntities();
public ActionResult Index()
{
Picture ds = new Picture();
var item = (from d in db.Pictures
select d).ToList();
return View(item);
}
あなたが指示したとおりに試しましたが、動作しませんでした。デバッグがブレークポイントで停止しました。 –
例外はありますか? – Shyju
エラーが表示されない場合、ブラウザーはほとんど検索しないとコントローラー・ファイルにリダイレクトされます。 VSには何のエラーもありません。 –