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

推荐订阅源

V
Vulnerabilities – Threatpost
P
Proofpoint News Feed
The Hacker News
The Hacker News
Know Your Adversary
Know Your Adversary
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
AWS News Blog
AWS News Blog
S
Securelist
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
IT之家
IT之家
腾讯CDC
WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
C
Check Point Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Engineering at Meta
Engineering at Meta
Latest news
Latest news
A
About on SuperTechFans
The Register - Security
The Register - Security
L
LINUX DO - 热门话题
T
The Exploit Database - CXSecurity.com
C
Cisco Blogs
T
Tailwind CSS Blog
Simon Willison's Weblog
Simon Willison's Weblog
阮一峰的网络日志
阮一峰的网络日志
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
T
Tor Project blog
L
Lohrmann on Cybersecurity
G
GRAHAM CLULEY
B
Blog RSS Feed
Scott Helme
Scott Helme
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
NISL@THU
NISL@THU
P
Privacy International News Feed
Security Latest
Security Latest
Recorded Future
Recorded Future
L
LangChain Blog
Cyberwarzone
Cyberwarzone
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
Last Week in AI
Last Week in AI
Apple Machine Learning Research
Apple Machine Learning Research
F
Fortinet All Blogs
O
OpenAI News
T
Threat Research - Cisco Blogs
Blog — PlanetScale
Blog — PlanetScale

博客园 - 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返回,在前台转换一下,一切正常