Asp.NET MVC 5从数据库显示图像

问题描述:

我试图从我的数据库显示图片。 首先我做一个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

我想你应该改变:

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

这样:

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

通过你的照片它的外观像

有一个表并且大部分是其中一个文件