解决ASP.NET 下 Easyui Form提交到ApiController,返回JSON结果,IE提示下载相关问题

前言

在使用Easyui框架进行文件的上传操作时,由前台Form提交到ApiController,返回JSON结果,IE提示下载。

产生原因

由于使用EasyuiForm表单进行上传时,Form默认析格式是"text/plain"。所以,使用IE(ps:其他浏览器不会出现这个问题)进行上传的时候,返回Json会提示下载。

解决方法

在后台,返回Json时,添加以下代码即可。如下代码所示:

string result_msg="{"Json":"Json字符串"}";
var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
HttpContent content = response.Content;
response.Content = new StringContent(result_msg);
return response;

前台,使用$.parseJSON();string转成对象获取相对应的值即可。如下代码所示:

var m_Json=$.parseJSON(d);
var m_Msg=m_Json.msg;
原文地址:https://www.cnblogs.com/ZengJiaLin/p/14078385.html