本文介绍了如何从数据库获取图片路径并在视图上显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
各位大家好,按照用户的建议,这里我存储的是我数据库中我的图片中的路径(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...
推荐答案
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();
这篇关于如何从数据库获取图片路径并在视图上显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!