Mvc 上传图片
?
VIEW 代碼
@using (Html.BeginForm("Upload", "UploadFile", FormMethod.Post, new { enctype = "multipart/form-data" }))
{???
?<input type="file" name="file" />???
?<input type="submit" value="OK" />
?}
?
Controller 代碼
????????? [HttpPost] ???????
?public ActionResult Upload(HttpPostedFileBase 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("~/Content/File"), fileName);????
?????????????? file.SaveAs(path);?????? ?????????
??????? ?}??? ?????????
???????? // redirect back to the index action to show the form once again?? ??????
??????? ?return RedirectToAction("Index");?????
?}
?
?
轉載于:https://www.cnblogs.com/a546558309/archive/2012/03/26/2417583.html
總結
- 上一篇: POJ2941 SDUT2371Homo
- 下一篇: 深入探讨用位掩码代替分支(3):VC6速