ASP.NET MVC에서 파일을 업로드 할 때 문제가 있습니다. 내 코드는 다음과 같습니다 :HttpPostedFileBase는 ASP.NET MVC에서 항상 null을 반환합니다.
보기 :
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index2</h2>
@using (Html.BeginForm("FileUpload", "Board", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" />
<input type="submit" />
}
컨트롤러 :
[HttpPost]
public ActionResult FileUpload(HttpPostedFileBase uploadFile)
{
if (uploadFile != null && uploadFile.ContentLength > 0)
{
string filePath = Path.Combine(Server.MapPath("/Temp"), Path.GetFileName(uploadFile.FileName));
uploadFile.SaveAs(filePath);
}
return View();
}
그러나 UploadFile로는 항상 null를 돌려줍니다. 누구나 알아낼 수 있습니까 ??
와우와 감사 버전을 사용해야 함을 의미한다. 이 MVC에 대해서는 전혀 몰랐습니다. ASP.NET MVC를 처음 접했습니다. 감사. –
필드 이름을 놓치지 않았지만 양식 정의에서 enctype 매개 변수가 누락되어 'null'문제가 발생했습니다. 예를 들어 주셔서 감사합니다. – niallsco
@ dotnetstep thanks – anpatel