1

Let me first be clear about what I'm not asking. I can see that the native ASP.NET MVC Ajax.BeginForm does not handle posting files from within an AJAX form post. There are answers I've seen that seem to establish this fact, and to offer an assortment of workarounds via jQuery plugins, etc:

Ajax.BeginForm in MVC to upload files

File upload with ajax in asp.net mvc

I'm not asking whether it can't be done, and I'm not asking for a workaround. I'm hoping someone can explain why it can't be done.

How is the AJAX form post being handled in MVC such that file inputs do not post? I guess I had always assumed that it was being handled at a base level just like a full post, but with some javascript trimmings that prevented a full page reload. Apparently that's not the case. Is the form submitted via javascript something like jQuery's $('#form').submit()? What's happening under the covers?

Community
  • 1
  • 1
jdmcnair
  • 1,305
  • 15
  • 33
  • It's still not clear to me. A standard HTTP POST is usually a url encoded string, or multipart/form-data MIME type. Both of those types also boil down to text... it is ultimately possible to string encode binary data. And I'm not so sure that it's universally true that AJAX requests use XML type data. I know that a lot of client-side code talks with the server in JSON. Still, I'd love to see a well written, well referenced answer discussing the specific differences between an AJAX post and a standard HTTP post. Thanks for the response. – jdmcnair Aug 16 '14 at 05:49
  • The above comment was in response to another comment that had been made and subsequently removed. The comment basically stated that AJAX calls couldn't handle files because AJAX calls are XML content type, and XML can't contain binary data. I don't know what parts of that are true, if any. I'm leaving my response... maybe it exposes more of my (wrong) assumptions? – jdmcnair Aug 16 '14 at 21:22
  • 1
    I've been wondering exactly the same as you for a while and still have no answer. In my research I particularly found one comment that took my attention: it is in the first paragraph of this Dustin Horne's post (http://www.dustinhorne.com/post/2011/11/16/AJAX-File-Uploads-with-jQuery-and-MVC-3), and it says: "...This is due to browser security restrictions and sandboxing...". Of course this is not the answer we are looking for, but might be an initial clue. Maybe this says something to you... – Iago Rodríguez Dec 01 '14 at 13:06
  • Thanks for the comment, and the link. The thing about the security restrictions and sandboxing is the closest to an explanation I've seen, even if it's not the full technical answer. – jdmcnair Dec 01 '14 at 20:01

0 Answers0