ASP.NET MVC and AjaxFileUpload

Okay, this is driving me crazy. I've tried to figure this out forever. I want to do an asynchronous upload using ajaxFileUpload . I have a message that the file for my controller is just fine, however, when I try to return a JsonResult from it, I get a Save File As dialog. I've tried everything to get around this and I either get an error or the Save As dialog. I'm guessing it has something to do with the type of content that is sent when the file is uploaded. I would really appreciate it if anyone could help. Thanks in advance!

+1


a source to share


4 answers


I had the same problem and solved it with



 public ContentResult UploadFile(FormCollection form, ...


  return Content("{success: false, ErrorMsg: 'someerror'}");

      

+5


a source


Greetings the following link will help you contain the whole ajax upload file using 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

+1


a source


If you look at the code there, it actually creates a new form and iframe, and then POSTing the form to the iframe. The response is returned to the iframe, which is then received and returned by code. My guess is that if you downloaded the JsonResult right in the browser, this will also trigger the download popup. Check the headers returned by the JsonResult to understand why, when loaded as a page, it thinks it is loading. Maybe you need to set Content-Type to text / plain or remove Content-Disposition header.

+1


a source


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");

      

+1


a source







All Articles