Click here to Skip to main content
15,886,578 members
Articles / Web Development / ASP.NET
Tip/Trick

Internet Explorer 9 JsonResult Does Not Return Json in MVC3

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
22 Nov 2015CPOL 11.9K   4   2
Internet Explorer 8/9 jsonresult method treats response as downloadable json result

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.

JavaScript
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);
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
Software developer in Microsoft technologies ASP.NET, C# ,MVC,KNOCKOUT JS, TELRICK CONTROL, JQUERY, BOOTSTRAP, ORACLE ,SQL SERVER,ENTITY FRAMEWORK,php, oracle

Comments and Discussions

 
Praisegreat Pin
Member 121860504-Dec-15 2:53
Member 121860504-Dec-15 2:53 
SuggestionClarifications and Suggestions Pin
RobTeixeira24-Nov-15 10:46
RobTeixeira24-Nov-15 10:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.