I am using file upload functionality in my asp.net MVC project.
It worked great until I started using some AJAX functionality on my page.
The HttpPostedFile is always NULL on Ajax page.
How can solve this issue along with calling ajax on my page?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because you cannot upload files using AJAX I would recommend you the excellent jquery form plugin which allows you to ajaxify your forms and supports file uploads. Behind the scenes the plugin generates a hidden iframe to handle the upload and is completely transparent to you:
Controller:
And finally ajaxify the form:
Also notice the usage of
HttpPostedFileBaseinstead ofHttpPostedFilein the controller action. Being an abstract class this will simplify your unit tests.