HttpPostedFileBase always return null in ASP.NET MVC

@{
    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" name="uploadFile"/>
  <input type="submit" />
}

you have to provide name to input type file to uploadFile in order to model binding work in ASP.net mvc and
also make sure that name of your input type file and argument name of HttpPostedFileBase is identical.

Leave a Comment