【发布时间】:2014-01-24 22:42:28
【问题描述】:
我已将文件保存在本地驱动器中,现在坚持将其取回屏幕。
场景-
public ActionResult Upload(HttpPostedFileBase file, CardModel card) {
CardTable cardtable = new CardTable();
if (file != null && file.ContentLength > 0) {
// TODO: storing uploaded files to the App_Data folder on the server.
// Adjust this location to fit your requirements
var drivepath = "D:\\FunRanger2\\FunRangerPhotos";
var filepath = Path.Combine(drivepath, Path.GetFileName(file.FileName));
file.SaveAs(filepath);
cardtable.CardFileName = file.FileName;
cardtable.CardFilePath = filepath;
cardtable.CardDate = DateTime.Now;
cardtable.CardTitle = card.cardTitle;
cardtable.CardHashCode = card.cardHashCode == null ? "" : card.cardHashCode;
db.CardTables.InsertOnSubmit(cardtable);
db.SubmitChanges();
}
例如,我将文件 - Desert.png 保存到此目录位置。
所以数据库CardFilePath 列更新到这个路径-
D:\FunRanger2\FunRangerPhotos\Desert.png
在视图方面-
我检查这条路径是否以模型值出现-
@Model.cardFilePath 是D:\FunRanger2\FunRangerPhotos\Desert.png
尝试在图像中获取它-
<img src="@Model.cardFilePath" height="300" width="300" />
我得到的只是那里没有图像。
如何在视图页面上获取此图像?
【问题讨论】:
-
如果您想将其保存在解决方案中的文件夹以外的其他文件夹中,请尝试像这样处理它们(放置 file:/// 前缀):file:///D:\FunRanger2\FunRangerPhotos\Desert .png
标签: c# asp.net asp.net-mvc asp.net-mvc-4