MVC返回JSON,IE下无法接收JSON,IE下JSON提示另存为

    public class JsonAttribute : ActionFilterAttribute 
    {
        /// <summary>
        /// 兼容IE下无法接受JSON问题
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            string contentType = filterContext.HttpContext.Response.ContentType;
            if (contentType == "application/json")
                filterContext.HttpContext.Response.ContentType = "text/html";


            base.OnResultExecuted(filterContext);
        }
    }

写一个过滤器,ContentType修改为"text/html",类名要以Attribute结尾

在Global.asax文件中注册过滤器

        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new JsonAttribute());
            filters.Add(new HandleErrorAttribute());
        }
原文地址:https://www.cnblogs.com/msbbc/p/3092625.html