0

当我在 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]它时加载但文件未上传...

谁能帮我?.......

4

1 回答 1

0

确保您正在创建如下表格,

@using (Html.BeginForm("Index", "Home", 
        FormMethod.Post,                
        new { enctype = "multipart/form-data" }))
{
    <input type="file" name="file" />
    <input type="submit" value="OK" />
}
于 2012-07-17T10:12:04.090 回答