HTML代码
<form method="post" action="~/Test/BaoMing" enctype="multipart/form-data">
<table>
<tr><td>附件:</td><td><input type="file" name="img"/></td></tr>
<tr><td colspan="1"></td><td><input type="submit" value="提交"/></td></tr>
</table>
</form>
后台代码
public ActionResult BaoMing()
{
return View();
}
[HttpPost]
public ActionResult BaoMing(HttpPostedFileBase img)
{
img.SaveAs(Server.MapPath("~/" + img.FileName)); //文件在项目根目录下
return Content("上传成功");
}