mvc3 file upload using ajax form - Request.Files empty

本小妞迷上赌 提交于 2019-11-29 08:35:34

You cannot upload files using AJAX. So replace the Ajax.BeginForm with a normal Html.BeginForm. You may checkout the following blog post as well.

If you want to use asynchronous uploads you may try some of the available upload components such as Ajax Upload and Uploadify.

First of all, I am not sure why you have this three times.

@Html.Partial("_UploadItem")
@Html.Partial("_UploadItem")
@Html.Partial("_UploadItem")

Are you trying to upload multiple files? There are quite a few scripts that allow you to do this quite efficiently. You are also generating multiple forms with fields that contain the same id. This wont effect the upload process, but is bad practice. I do think you need to refactor the above. Anyway change the field in your partial view to

<input type="file" name="file" />

I think the problem may be with your actual action and how you are trying to retrieve the file. Try this

HttpPostedFileBase postedFile = Request.Files["file"];

Let me know if that works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!