Tutorial :ASP.NET MVC and AjaxFileUpload


Ok, this is driving me nuts. I have been trying to figure this out forever now. I want to to perform an async upload using ajaxFileUpload. I have it posting the file to my controller just fine, however, when i try to return a JsonResult from it, I get a "Save File As" dialog box. I have tried everything to get around this and i either get an error or the "Save As" dialog. Im assuming that it has something to do with the content type that is being passed in when the file gets posted. I would be greatly appreciative if anyone could help. Thanks in advance!


I had the same problem and I solved it with

 public ContentResult UploadFile(FormCollection form, ...        return Content("{success: false, ErrorMsg: 'someerror'}");  


Hi hope that following link will help you it is containing the whole ajax file upload video with the asp.net mvc.



If you look at the code there, it's actually creating a new form and iframe, and then POSTing the form to the iframe. The response is written back to the iframe, which the code then picks up and returns. I'd assume if you loaded the JsonResult directly in a browser it would also cause the same download box to pop up. Check the headers that are being returned with the JsonResult to see why when being loaded as a page it thinks its a download. Maybe you need to set the Content-Type as text/plain or remove a Content-Disposition header.


In your controller only include "text/x-json" like this:

 public JsonResult UploadFile(FormCollection form, ...        return Json("{id: xxxx, text: 'bla bla bla'}", "text/x-json");  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »