まあ、これは奇妙です。私はウェブ上で大規模に見つけたようにすべてをやっていますが、それでも機能しません。ファイルをアップロードしたいので、ビューに次のように配置します。
@using (Html.BeginForm("Import", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="uploadFile" />
<input type="submit" value="Importa" />
}
これはホーム/インポートです:
[AcceptVerbs(HttpVerbs.Post)] // or [HttpPost], nothing changes
public ActionResult Import(HttpPostedFileBase uploadFile)
{
Debug.WriteLine("Inside Import");
if (uploadFile == null)
Debug.WriteLine("null");
// Verify that the user selected a file
if (uploadFile != null && uploadFile.ContentLength > 0)
{
Debug.WriteLine("Valid File");
...
}
}
そして、それは常にInside Import + nullを出力します。したがって、正しいコントローラーアクションを呼び出すと確信していますが、常にnullのHttpPostedFileBaseを受け取ります。
誰かがそれについてアドバイスを持っていますか、またはすでにこの種の問題を見つけた(そして解決した)のですか?ありがとう!