내가 무엇이 빠졌는지 모르지만 C# MVC 3을 사용하여 파일을 업로드해야합니다. 여기에 나온 지침을 따르지만 파일은 항상 비어 있습니다. 여기 MVC 3 파일 업로드 - 컨트롤러의 Null 파일
내 실제 테스트 코드 :HTML
@using (Html.BeginForm("Prc", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" id="file" />
<input type="submit" value="submit" />
}
컨트롤러
[HttpPost]
public ActionResult Prc(HttpPostedFile file)
{
if (file != null && file.ContentLength > 0)
{
var filename = System.IO.Path.GetFileName(file.FileName);
var path = System.IO.Path.Combine(Server.MapPath("~/Content/Images"), filename);
file.SaveAs(path);
}
return RedirectToAction("Index");
}
내가 웹 응용 프로그램을 실행하면, 내가 파일을 첨부하고 제출을 클릭합니다 . 그러나 Controller
에 도달하면 file
개체는 null
입니다. 항상 null
. XML
파일, JPEG
파일 및 GIF
파일을 시도했지만 어느 것도 작동하지 않았습니다.
이외의 코드를 구성해야합니까? 이러한 코드는 무엇입니까?
감사 MVC에서
나는 바보 같은 것을 놓친다는 것을 안다. 감사!! – Devmonster