zoukankan      html  css  js  c++  java
  • 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());
            }
  • 相关阅读:
    js发送请求
    GIS小知识
    oracle常见错误
    java异常Exception
    java获取文件路径
    Runnable和Thread的区别
    Hadoop shell命令
    Runtime和Process
    Linux下查看tomcat控制台输出信息
    ajax小知识
  • 原文地址:https://www.cnblogs.com/msbbc/p/3092625.html
Copyright © 2011-2022 走看看