Fix Internet Explorer prompts to save JSON response when uploading files

When you upload a file using AJAX and then reply using a JSON response, Internet Explorer decides to interpret the response as something to download to disk or open. In essence, it interjects in between the Ajax post response and turns the response into a standard IE file download.

To resolve this I looked at the HTTP headers from two posts made by IE. The first is the post with a file:

The response to this looks like this:

And then the second without a file, using a standard Ajax post:

With the resulting response:

In order to fix the problem I needed to change the content type of the response. Internet Explorer isn’t accepting application/json, and that is what ASP.NET MVC is sending back by default. A quick fix is to override the JsonResult in the base controller:

We now get text/plain back for browsers (IE) that aren’t ready to accept application/json. Problem solved.

Oak – Frictionless development for ASP.NET MVC single page web apps.

What is Oak?

Single page web apps are becoming the norm as opposed to the exception. And with that comes a large part of your code base existing on the client side with a lot of JavaScript, JSON and async HTTP. Oak gives you a way to quickly build these kind of apps by:

  • Bridging language barriers between JavaScript (a prototypical language) and C# (a statically compiled languge).
  • Leveraging C#’s 4.0 DLR to give your classes extremely powerful dynamic and prototypical capabilites.
  • Augmenting ASP.NET MVC to better support consuming and returning JSON payloads.
  • Providing a lean, fast, dynamic ORM to seamlessly save dynamic/prototypical classes.
  • Providing a holistic approach to develop, build, and test single page web apps.