困扰了很久的问题,终于解决了,解决方案连接:
http://stackoverflow.com/questions/13292173/asp-net-mvc-razor-uploading-file-httppostedfilebase-always-null
@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"); ... } }
需要在View中添加
@data_ajax="false"
。
呼,舒服~