Introduction
In Internet Explorer 8 and Internet Explorer 9, the JsonResult ActionResult
was returning the content-type
of the JSON result as application/json, which seems to make Internet Explorer want to download it. but other browsers were working fine. So we need to override the Jsonresult
method in order for it to work in all browsers.
The Code
So here, we use the base controller class that inherits from the controller
class, and we set the content type. So you don't need to set content type individually.
public class BaseController : Controller
{
protected new JsonResult Json(object data)
{
if (!Request.AcceptTypes.Contains("application/json"))
return base.Json(data, "text/plain");
else
return base.Json(data);
}
}