2017-11-12 4 views
0

지정된 경로의 형식은 지원되지 않습니다.이미지 URL이 데이터베이스에 저장되고 있지만 VS2015의 지정된 폴더에 이미지가 저장되지 않았습니다.

Path.Combine을 사용하려고 시도했지만 경로에서 '~'가 제거되었지만 이미지는 여전히 "Images"폴더에 저장되지 않습니다.

[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

'Server.MapPath ("~/Images /"+ fup.FileName')의 값은 무엇입니까? –

+0

그리고 관련이 없지만 뷰 모델을 사용하고 있기 때문에'HttpPostedFileBase PropertyImage' 속성을 포함해야합니다. 모델 –

+0

ViewModel의 속성은 public string PropertyImage –

답변

0

그것은 수정되었습니다 :

문자열 파일 이름 =는 Server.MapPath를 ("~"+ "\\ 이미지 \\"+ Path.GetFileName (fup.FileName)); fup.SaveAs (filename);

위의 코드는 이중 백 슬래시를 포함시킨 후 저에게 효과적이었습니다. :)

관련 문제