【发布时间】:2019-02-28 11:47:35
【问题描述】:
您好,我正在尝试将图像从本地文件夹添加到我的数据库中,并且工作成功,但使用路径保存,并且在索引页面上是 not displaying 没有图像,但在数据库上是 created value path
我有这个错误:
GET http://localhost:57079/'~/Content/img/Asp.net.svg.png'
这是创建方法:
public ActionResult Create( Article article,HttpPostedFileBase postedFile)
{
try
{
db = new IdentityDBEntities2();
if (ModelState.IsValid)
{
if (postedFile != null)
{
article.image = Convert.ToString(postedFile.ContentLength);
postedFile.InputStream.Read(System.Text.Encoding.Unicode.GetBytes(article.image), 0, postedFile.ContentLength);
string fileName = System.IO.Path.GetFileName(postedFile.FileName);
string FilePath = "~/Content/img/" + fileName;
postedFile.SaveAs(Server.MapPath(FilePath));
}
article.UserId = System.Web.HttpContext.Current.User.Identity.GetUserId();
article.Idc = Convert.ToInt32(Request["cab"]);
db.Articles.Add(article);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(article);
}
catch(Exception e) { Response.Write(e.Message); }
return View();
}
谢谢。
【问题讨论】:
标签: c# asp.net asp.net-mvc