当我在Controller中使用以下代码时
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
string path = Path.Combine(Server.MapPath("~/Images"),
Path.GetFileName(file.FileName));
file.SaveAs(path);
ViewBag.Message = "File Uploaded Successfully";
return View();
}
当我运行应用程序时,我收到了以下错误
---Server Error in '/' Application.
---The resource cannot be found.
当我删除[HttpPost]
时,它会加载,但文件未上传...
任何人都可以帮助我吗?.......
答案 0 :(得分:0)
确保您正在创建如下表单
@using (Html.BeginForm("Index", "Home",
FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="OK" />
}