您的位置:首页 > 其它

下载csv,excel文件名乱码的问题(IE和FireFox两种浏览器)

2013-07-09 18:02 435 查看
一.使用ajax与服务器交互 不管是post方式还是get方式都应该对中文进行编码 只有这样 服务器端(ie浏览器 firefox不用)才能正确解析汉字 否则就是乱码。

二.在asp.net MVC中 ie跟firefox对下载文件名的处理不同

/ ie通过编码实现正确的文件名/

public FileContentResult DownLoad()

{

string temp = "我是中国人!";

return File(System.Text.Encoding.UTF8.GetBytes(temp), "text/plain",Url.Encode("中国.txt"));

}

/firefox不必编码否则出现编码后的文件名/

public FileContentResult DownLoad()

{

string temp = "我是中国人!";

return File(System.Text.Encoding.UTF8.GetBytes(temp), "text/plain","中国.txt");

}

兼容firefox跟ie的做法

通过Request.Browser.Browser.ToUpper()来判断是ie还是firefox

详细网址参照:
http://www.cnblogs.com/chengxiaohui/articles/1985163.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐