我上传图片:为什么不找一个资源
[HttpPost]
public ActionResult Create(PlaceViewModel model)
{
if (ModelState.IsValid)
{
string fileName = Guid.NewGuid().ToString() + ".jpg";
string serverPath = Server.MapPath("~");
string imagesPath = serverPath + "Content\\Uploads\\";
string thumbPath = imagesPath + "Thumb\\";
string fullPath = imagesPath + "Full\\";
ImageModel.ResizeAndSave(thumbPath, fileName, model.ImageUploaded.InputStream, 100, true);
ImageModel.ResizeAndSave(fullPath, fileName, model.ImageUploaded.InputStream, 600, true);
model.Image = fileName;
var place = new Place();
model.ConvertToData(place);
_placeRepository.Add(place);
_placeRepository.SaveChanges();
return RedirectToAction("Index");
}
return View(model);
}
文件上传和在磁盘上存在物理
我从HTML调用图像:
<img height="100px" src="/Content/Uploads/Thumb/833c4384-884d-4250-982c-d5df0fa875ef.jpg" width="100px"/>
但我不看不到这张图片。
如果我打电话localhost:23354/Content/Uploads/Thumb/833c4384-884d-4250-982c-d5df0fa875ef.jpg
我有错误:
The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Content/Uploads/Thumb/833c4384-884d-4250-982c-d5df0fa875ef.jpg
我究竟做错了什么?
是在您的网址的根内容?您正在请求/内容中的图片,但是当您上传图片时,您已将其上传到〜/ content/...他们是否是同一位置? – Brettski
为什么在这个问题上有两个反对票? – Brettski
我同意Brettski。这是一个完全有效的问题。从我+1。 –