我想知道爲什麼我的圖像不顯示。我已將圖像的地址存儲在列名ImageArticle中。我試圖在MVC項目中的所有字段之後顯示此圖像。這是代碼。圖像不顯示
Index.cshtml
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Phone)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
<img src="@Html.DisplayFor(modelItem => item.ImageArticle)" /> <== here is the image
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
</table>
這裏是我把在DB領域ImageArticle定義:〜/圖片/ phone.jpg
下面是當我跑的應用程序創建的HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<p>
<a href="/Home/Create">Create New</a>
</p>
<table class="table">
<tr>
<th>
FirstName
</th>
<th>
LastName
</th>
<th>
Phone
</th>
<th>
Email
</th>
<th>
ImageArticle
</th>
<th></th>
</tr>
<tr>
<td>
Joe
</td>
<td>
Bloe
</td>
<td>
222-222-3344
</td>
<td>
[email protected]
</td>
<td>
<img src="~/Images/phone.jpg" /> <== this image should show up correctly?
</td>
<td>
<a href="/Home/Edit/1">Edit</a> |
<a href="/Home/Details/1">Details</a> |
<a href="/Home/Delete/1">Delete</a>
</td>
</tr>
<tr>
<td>
Paul
</td>
<td>
Statsny
</td>
<td>
333-444-5544
</td>
<td>
[email protected]
</td>
<td>
<img src="dshfs" />
</td>
<td>
<a href="/Home/Edit/2">Edit</a> |
<a href="/Home/Details/2">Details</a> |
<a href="/Home/Delete/2">Delete</a>
</td>
</tr>
</table>
在VS解決方案資源管理器中,我創建了一個名爲Images的文件夾,其中放置了phone.jpg。
但是圖片沒有顯示在屏幕上。
感謝
正是我在找的東西。謝謝 – user3127986