1
我是MVC的新手。我的照片儲存在名爲「Resim」的表格中。 MVC中的顯示圖像[VARBINARY(MAX)]
我想從視圖中調用關聯記錄時看到圖片,我將使用其ID來調用它。這裏是我的控制器代碼:
public ActionResult Details(int id = 0)
{
SozlukEntities db = new SozlukEntities();
KelimeTuru kelime = db.KelimeTuru.Find(id);
if (kelime == null)
{
return HttpNotFound();
}
return View(kelime);
}
這是我認爲的代碼:
@model SozlukRG.Models.KelimeTuru
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<fieldset>
<p>Move the mouse pointer over this paragraph.</p>
<legend>KelimeTuru</legend>
<div class="div1" style="display: table; background-color: #b0c4de;">
<div class="div1" style="display: table-row;">
<div class="div1" style="display: table-cell; padding: 10px;">
@Html.DisplayNameFor(model => model.KelimeId)
</div>
<div class="div1" style="display: table-cell; padding: 10px;">
@Html.DisplayNameFor(model => model.VideoId)
</div>
<div class="div1" style="display: table-cell; padding: 10px;">
@Html.DisplayNameFor(model => model.ResimId)
</div>
<div class="div1" style="display: table-cell; padding: 10px;">
@Html.DisplayNameFor(model => model.Anlam)
</div>
</div>
<div class="div1" style="display: table-row;">
<div class="div1" style="display: table-cell; padding: 10px;">
@Html.DisplayFor(model => model.KelimeId)
<div class="div1" style="display: table-cell; padding: 10px;">
<video width="320" height="240" controls>
<source src="/Videos/b.mp4" type="video/mp4">
</video>
</div>
<div class="div1" style="display: table-cell; padding: 10px;">
@*The Image will be inserted here, PLEASE HELP ME WITH THIS :) *@
</div>
<div class="div1" style="display: table-cell; padding: 10px;">
@Html.DisplayFor(model => model.Anlam)
</div>
</div>
</div>
</fieldset>
<p>
@Html.ActionLink("Back to List", "Index")
</p>
Resim
是表的名稱和Adi
是VARBINARY(MAX)
柱與圖片。我想在視圖中看到圖片。 事先請Help..Thanks ...
這是正確的嗎? ' 公共的ActionResult showImg(INT ID) { SozlukEntities分貝=新SozlukEntities(); KelimeTuru kelime = db.KelimeTuru.Find(id); var stream = kelime.Resim.Adi; return File(stream,「image/jpeg」); } @ –
@RuhiGoktas是的,應該這樣做。 –