我如何在MVC视图中从数据库获取图像 [英] How I get image from database in MVC view
问题描述
你好专家
我在服务器和数据库中存储图像存储了该图像的路径现在我想在剃刀视图上查看图像。
请帮助
谢谢
我尝试了什么:
i尝试了这个,但获得所有产品的相同图像
< img src =@ Url.Content(/ Images / image.jpg)width =100height =100/>
如果我使用下面的我得到null不显示任何东西
< img src =@ Url .Content(item.Image1)alt =/>
数据库中的
Image1(列)有图像路径
hello experts
I stored image on server and in database stored the path of that image now i want to view image on razor view.
Please help
Thank You
What I have tried:
i tried this but get same image for all product
<img src="@Url.Content("/Images/image.jpg")" width="100" height="100" />
if i use below i get null not display anything
<img src="@Url.Content(item.Image1)" alt="" />
in database Image1(column) have path of the image
推荐答案
请阅读本文,可能帮助你:
我如何从MVC视图中的数据库获取图像
Please read this, It may be help you:
How I get image from database in MVC view
您需要确保图像存储在Web根目录中,以便客户可以访问它。接下来而不是将文件的路径存储在光盘上(c:\inetpub \ www.root \ site \ images /\\ image.jpg),你应该存储相对于你的web根目录的路径,所以像〜/图像/ image.jpg的。这将为你提供一条你可以使用的路径
You need to make sure the image is stored inside the web root so that clients can access it. Next rather than storing the path to the file on disc (c:\inetpub\wwwroot\site\images\image.jpg), you should store the path relative to your web root, so something like "~/images/image.jpg". That will give you a path you can use like this
<img src="@Url.Content(item.ImagePath)" alt="" />
如果你真的需要存储其他东西的实际路径,那么你可以存储实际路径以及相对于站点根目录的路径。
If you really need the actual path stored for something else then you can store both the actual path as well as the path relative to the site root.
这篇关于我如何在MVC视图中从数据库获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!