// This action renders the form public ActionResult Upload() { return View(); } // This action handles the form POST and the upload [HttpPost] public ActionResult Upload(HttpPostedFileBase file) { // Verify that the user selected a file if (file ! = null && file.ContentLength > 0) { // extract only the fielname var fileName = Path.GetFileName(file.FileName); // store the file inside ~/App_Data/uploads folder var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); file.SaveAs(path); } // redirect back to the index action to show the form once again return RedirectToAction("Index"); }
Html.BeginForm()
`Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" })`.
<httpruntime maxrequestlength="" x"="" />`