2017-05-06 99 views
0

我試圖從我的數據庫顯示圖片。 首先我做一個ShopModels.cs該車型內部模型我有這個(我認爲這是很好的現在):Asp.NET MVC 5從數據庫顯示圖像

public class ShopModels 
    { 
     public int Id { get; set; } 
     public string Title { get; set; } 
     public string Photo { get; set; } 
     public decimal Price { get; set; } 
    } 
} 

而且我做了模型之後,我已經架式我的控制器和視圖 在我的控制器中我做了沒有改變任何東西的圖像只爲其他事情。 而對於我的視圖(稱爲視圖文件夾:ShopModels)所謂Detials.cshtml

而且我Detials.cshtml裏面我已經改變了這一點:

@Html.DisplayFor(model => model.Photo) 

這樣:

<img src="@Url.Content(@Model.Photo)" /> 

它仍然不起作用,它也不會給我一個錯誤。


我的數據庫看起來是這樣的: 我已經tryed試圖改變

圖片/ JohnSmith.png

〜/圖片/ JohnSmith對。 png

但仍沒有運氣

enter image description here

樹:

enter image description here

這是與結果是什麼我越來越: enter image description here

正如你可以看到我得到文本而不是結果。

+0

如果您訪問http:// localhost:,您能看到您的圖片嗎?/Photos/JohnSmith.png在瀏覽器中? - 明顯地取代適用 – Alex

+0

是的我可以當我改變它的代碼它也可以,但這不是來自數據庫: Deniz

回答

0

我想你應該改變:

@Html.DisplayFor(model => model.Photo) 

這樣:

<img src="@Url.Content(@Model.Photo)" /> 
在Index.cshtml或Shop.cshtml

通過你的照片它的外觀像

有一個表並且大部分是其中一個文件