惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
O
OpenAI News
D
Docker
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
N
Netflix TechBlog - Medium
人人都是产品经理
人人都是产品经理
Y
Y Combinator Blog
M
MIT News - Artificial intelligence
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 司徒正美
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
K
Kaspersky official blog
Security Latest
Security Latest
T
Tailwind CSS Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
V
Vulnerabilities – Threatpost
W
WeLiveSecurity
N
News and Events Feed by Topic
aimingoo的专栏
aimingoo的专栏
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security
爱范儿
爱范儿
宝玉的分享
宝玉的分享
腾讯CDC
H
Heimdal Security Blog
Webroot Blog
Webroot Blog
AI
AI
WordPress大学
WordPress大学
Recorded Future
Recorded Future
SecWiki News
SecWiki News
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
C
Check Point Blog
TaoSecurity Blog
TaoSecurity Blog
Cisco Talos Blog
Cisco Talos Blog
The Cloudflare Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - Franky
云风的 BLOG
云风的 BLOG

博客园 - hemingchen

MiniProfiler Delphi XE2 新技术说明 (What's new in Delphi XE2)(转载) Microsoft.VisualStudio.Xaml 加载错误 解决 网页如何有效调用exe js parentElement - hemingchen - 博客园 Response.ContentType 详细列表 - hemingchen - 博客园 SQL 2005 开启OpenRowset/OpenDatasource的办法 常用正则表达式 - hemingchen - 博客园 XMLHTTP 保护自己的眼睛 转载 37个Ajax和CSS实现的Tab选项卡切换效果界面 SQL2005附加数据库"失败........无法更新数据库"xxx",因为数据库是只读 - hemingchen - 博客园 asp.net C# 下母版页使用 .net Access 新增记录后获取自动编号的值 JavaScript 脚本文件编码导致的问题 jquery json简单例子 jquery ajax xml jquery学习 使用面向对象的技术创建高级 Web 应用程序 文章来源:http://msdn.microsoft.com/zh-cn/magazine/cc163419.aspx本文讨论:
asp.net MVC控制器中返回JSON格式的数据时提示下载
hemingchen · 2015-09-01 · via 博客园 - hemingchen

 Asp.net mvc在接收的是JSON格式的数据,但是奇怪的是在IE中提示下载文件,其他浏览器中一切正常,下载后,里面的内容就是在控制器中返回的数据。代码如下:

视图中js代码:

   $("#form").ajaxSubmit({
                    type: "POST",
                    url: "/controller/action/",
                    datatype: "json",
                    success: function (data) {
                      alert(data.Msg);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                    }
                });

控制器中的代码是:

ResultJsonInfo 为自定义类

 public JsonResult DoUploadModel(Model3DInfo model)
        { 

      //其他代码省略
                return Json(new ResultJsonInfo() { Result = true, Msg = "保存成功!" });

        }

解决方法如下,只需要修改两点,修改过的代码如下:

控制器中:

public JsonResult DoUploadModel(Model3DInfo model)
        { 

     ...
            return Json(new ResultJsonInfo() { Result = true, Msg = "保存成功!" }, "text/html");
        }

视图中:

   $("#formDoUpload").ajaxSubmit({
                    type: "POST",
                    url: "/controller/action/",
                    datatype: "json",
                    success: function (data) {
                           data = JSON.parse(data); 

          alert(data.Msg);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                    }
                });

红色的部分就是我修改的地方,让其返回按照text/html返回,在前台转换一下,一切正常