0
저는 ASP.net MVC 5를 사용하고 있습니다. 아래의 코드는 파일을 저장하는 데 작동하지만 요청에 업로드 된 파일을 추출해야 파일을 메소드에 전달할 수 있습니다. 다른 클래스에서 파일 서버에 업로드하기 전에 유효성 검사를해라. 그 Request.Files [upload] .SaveAs 아래에 파일이 포함되어 있지만 파일을 다른 클래스로 전달하려면 어떻게해야합니까? HttpPostedFileBase 파일을 다른 클래스에 전달하려고 시도했지만 파일을 인식하지 못합니다. 내보기에서요청에서 파일 압축 풀기
:
@using (Html.BeginForm("FileUpload",
"Upload",
FormMethod.Post,
new { enctype = "multipart/form-data" }))
{ <label for="file">Upload Image:</label>
<input type="file" name="FileUpload" /><br />
<input type="submit" name="Submit" id="Submit" value="Upload" />
}
내 컨트롤러 :
public ActionResult FileUpload(HttpPostedFileBase file)
{
//HttpPostedFileBase request = file;
foreach (string upload in Request.Files)
{
System.Diagnostics.Debug.WriteLine("*********************savepath:" + Request.Files[upload].FileName+"********************");
string savePath = "C:\desktop";
string newPathForFile = Path.Combine(savePath, Path.GetFileName(Request.Files[upload].FileName));
Request.Files[upload].SaveAs(Path.Combine(savePath, newPathForFile));
}
return View("Home");
}
가능하면 코드 예제 바랍니다. .net MVC newbie here. 지금까지 MVC 만 3 일. – ConfusedDeer
구현 방법을 찾았습니다. 지도 해줘서 고마워. – ConfusedDeer