views:

362

answers:

3

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!

A: 

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

jalpesh
I appreciate the prompt reply, however, the demo that you provided uses silverlight to provide the upload capability. Im trying to create the ajax upload functionality without requiring the user to download a plugin (also why I havent implemented SWFUpload).
+1  A: 

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.

plug

My SlickUpload ASP.NET upload control handles all these issues and more in an easy to implement control. It's also the only control I'm aware of that supports ASP.NET MVC. Take a look at the AspNetMvc sample in the Samples/Advanced folder...

Chris Hynes
+1  A: 

I had the same problem and I solved it with

public ContentResult UploadFile(FormCollection form, ...

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

vprorok
your solution worked for me too....thanks for sharing :-)
Raja