JSON Action Results and Internet Explorer

I had an issue recently where my MVC action was returning some JSON as a result. The issue occurred when Internet Explorer (possibly only earlier versions) got the JSON response, it thought the response should be delivered to the browser. This is quite undesirable.

A simple way that I found to fix this was to specify the content type and encoding of the JSON response using the built-in MVC methods.

public ActionResult Index(int id)
{
        // Fetch some data
        var someData = GetSomeData();

        // Return and update content type and encoding
        return Json(someData, "text/html", System.Text.Encoding.UTF8,
                        JsonRequestBehavior.AllowGet);
}

Til next time ...