在调试/测试时,我一直在尝试将传入的上传图像保存在我的开发机器上的 ~/Content 中,但没有文件被传输到那里。该文件夹是否允许将图像保存/传输到它,或者我需要将它们保存在 ~/App_Data 中吗?
编辑:我正在使用的代码:
public ActionResult(AdminGameEditModel formData)
{
Game game = new Game();
AutoMapper.Mapper.Map<AdminGameEditModel, Game>(formData, game);
if (formData.BoxArt.ContentLength > 0 && formData.IndexImage.ContentLength > 0)
{
var BoxArtName = Path.GetFileName(formData.BoxArt.FileName);
var BoxArtPath = Path.Combine(Server.MapPath("~/Content/Images/BoxArt"), BoxArtName);
game.BoxArtPath = BoxArtPath;
formData.BoxArt.SaveAs(BoxArtPath);
var IndexImageName = Path.GetFileName(formData.IndexImage.FileName);
var IndexImagePath = Path.Combine(Server.MapPath("~/Content/Images/GameIndexImages"), IndexImageName);
game.IndexImagePath = IndexImagePath;
formData.IndexImage.SaveAs(IndexImagePath);
}
// rest of controller method
}
这两个文件都是HttpPostedFileBase
对象。我目前使用的服务器只是在 VS 调试期间运行的 ASP.NET 服务器。