Tutorial :ASP.NET MVC and AjaxFileUpload



Question:

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!


Solution:1

I had the same problem and I solved it with

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


Solution:2

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

http://stephenwalther.com/blog/archive/2008/10/03/asp-net-mvc-application-building-family-video-website-5-multiple-file-upload-with-progress.aspx


Solution:3

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.


Solution:4

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
Previous
Next Post »