MVC 4 Razor文件上传我是新的MVC 4,我试图在我的网站实现文件上传控制。我找不到错误,我在我的文件中得到了一个空值。主计长: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" />}
3 回答
RISEBY
TA贡献1856条经验 获得超5个赞
Upload
HttpPostedFileBase
file input
.
<input type="file" name="file" />
Request.Files
:
[HttpPost]public ActionResult Upload(){ if (Request.Files.Count > 0) { var file = Request.Files[0]; 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"); }
- 3 回答
- 0 关注
- 488 浏览
添加回答
举报
0/150
提交
取消