不支持给定路径的格式。
尝试使用Path.Combine,删除'〜'从路径,但图像仍然没有保存在"图像"文件夹中。
[HttpPost]
public ActionResult Create(PropertyViewModel propertyViewModel)
{
if (ModelState.IsValid)
{
Property property = new Property();
property.Id = propertyViewModel.Id ?? 0;
property.PropertyCost = propertyViewModel.PropertyCost;
property.PropertyDescription = propertyViewModel.PropertyDescription;
HttpPostedFileBase fup = Request.Files["PropertyImage"];
if(fup!=null)
{
property.PropertyImage = fup.FileName;
fup.SaveAs(Server.MapPath("~/Images/" + fup.FileName));
//string path = "~/Images/"+fup.FileName;
////string combinedPath = System.IO.Path.Combine(path,fup.FileName);
//fup.SaveAs(Server.MapPath(path));
}
_propertyQueryProcessor.Create(property);
}
return RedirectToAction("Index");
}
答案 0 :(得分:0)
现在修复:)
string filename = Server.MapPath(“〜”+“\\ Images \\”+ Path.GetFileName(fup.FileName)); fup.SaveAs(文件名); 强>
在包含那些双反斜杠后,上面的代码对我有用。 :)