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 に答える