MVC 4 Razor文件上传
public class UploadController : BaseController { public ActionResult UploadDocument() { return View(); } [HttpPost] public ActionResult Upload(HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Images/"), fileName); file.SaveAs(path); } return RedirectToAction("UploadDocument"); } }
@using (Html.BeginForm("Upload", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" })){ <input type="file" name="FileUpload" /> <input type="submit" name="Submit" id="Submit" value="Upload" />}
RISEBY