HttpPostedFileBase всегда возвращает null в ASP.NET MVC

У меня проблема, когда я загружаю файл в ASP.NET MVC. Мой код ниже:

View:

@{
    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" />
}

Controller:

[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. Кто-нибудь может выяснить почему?

51
задан tereško 14 July 2012 в 15:24
поделиться