好吧,這很奇怪。 我正在盡一切努力,因爲我在網上大量找到,但仍然無法正常工作。 我要上傳文件,所以在查看我把:ASP.NET MVC Razor - 上傳文件,HttpPostedFileBase總是爲空
@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");
...
}
}
,它總是打印內部導入 + 空。所以我相信我會調用正確的Controller Action,但它總是會收到一個空的HttpPostedFileBase。
有沒有人有任何建議,或已經找到(並解決)這種問題? 謝謝!
您是否嘗試過使用HTML表單標籤而不是Razor幫助程序? – Derek
我做了數以億計的事情,試圖找出它,所以我不記得很好......但我想我試過了!沒有結果。不過,我會再試一次。所以,請繼續關注,你會有我的消息,謝謝! – Jack88PD
好的,它也不能使用HTML表單標籤。所以我想我以前也試過這個;)真的不知道爲什麼它不適用於我,而其他人都這麼做。 – Jack88PD