I have a data base with images I can get the Image tag to show in the browser but no image Is there an artical or tutorial that will show how to display Image fron database in MVC my tables have GUID userId
我有一个带有图像的数据库我可以在浏览器中显示Image标签,但是没有图像是否有一个艺术或教程将展示如何在MVC中显示图像fron数据库我的表有GUID userId
2 个解决方案
#1
1
render a view that has image links something like this
渲染具有图像链接的视图
<img src="http://www.yourwebsite.com/mycontroller/renderimageaction/imageid">
in the code of mycontroller, create a renderimageaction, in it go and look for image "imageid" in the database, read the image data, and return the data to the browser as a content-type "image/jpg" or other suitable type depending on what you have stored your images as in the database
在mycontroller的代码中,创建一个renderimageaction,在其中去查找数据库中的图像“imageid”,读取图像数据,并将数据作为内容类型“image / jpg”或其他合适的类型返回到浏览器取决于您在数据库中存储图像的内容
#2
0
Generate the image source point to a web url which will query the database and put them into the response stream with correct MIME type.
生成图像源指向Web URL,该URL将查询数据库并将其放入具有正确MIME类型的响应流中。
With Asp.NET routing you can even do something like http://somehost/image/logo.jpg
where "image
" is actually an action to pull the image from DB. This way the user can preserve picture name when they save picture to their local drives.
使用Asp.NET路由,您甚至可以执行类似http://somehost/image/logo.jpg的操作,其中“image”实际上是从DB中提取图像的操作。这样,用户可以在将图片保存到本地驱动器时保留图片名称。
#1
1
render a view that has image links something like this
渲染具有图像链接的视图
<img src="http://www.yourwebsite.com/mycontroller/renderimageaction/imageid">
in the code of mycontroller, create a renderimageaction, in it go and look for image "imageid" in the database, read the image data, and return the data to the browser as a content-type "image/jpg" or other suitable type depending on what you have stored your images as in the database
在mycontroller的代码中,创建一个renderimageaction,在其中去查找数据库中的图像“imageid”,读取图像数据,并将数据作为内容类型“image / jpg”或其他合适的类型返回到浏览器取决于您在数据库中存储图像的内容
#2
0
Generate the image source point to a web url which will query the database and put them into the response stream with correct MIME type.
生成图像源指向Web URL,该URL将查询数据库并将其放入具有正确MIME类型的响应流中。
With Asp.NET routing you can even do something like http://somehost/image/logo.jpg
where "image
" is actually an action to pull the image from DB. This way the user can preserve picture name when they save picture to their local drives.
使用Asp.NET路由,您甚至可以执行类似http://somehost/image/logo.jpg的操作,其中“image”实际上是从DB中提取图像的操作。这样,用户可以在将图片保存到本地驱动器时保留图片名称。