如何从数据库获取图片路径并在视图上显示它 [英] How to get a picture route from the database and show it on the view

查看:89
本文介绍了如何从数据库获取图片路径并在视图上显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位大家好,按照用户的建议,这里我存储的是我数据库中我的图片中的路径(ServerPath),我需要在我的View中显示它们,但我不知道怎么做,请,需要你的帮助,谢谢......

Hello everyone, following the advises from a user here I'd store are the routes (ServerPath) from my pictures in my database, and I need to show them in my View, but I don't know how to do it, please, need your help, thanks...

推荐答案

您好,我是在朋友的帮助下自己做的,谢谢大家的帮助,这是保存数据库路径的代码:

Hello, I did it by myself with the help of a friend, thanks all of you for the help, here is the code to save the path to the database:
if (file != null && file.ContentLength > 0)
{
    // extract only the fielname
    var fileName = Path.GetFileName(file.FileName);
    // store the file inside ~/App_Data/uploads folder
    var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); 
    image.Picture = fileName;
}



并返回文件并将其显示在以下视图中:


and to return the file and show it to the view this one:

var path = ControllerContext.HttpContext.Server.MapPath("/");
if (System.IO.File.Exists(Path.Combine(path, file)))
{
   return File(Path.Combine(path, file), "image/jpeg");
}
return new HttpNotFoundResult();


这篇关于如何从数据库获取图片路径并在视图上显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆