如何强制ASP.NET MVC以UTF-8格式读取.cshtml文件? [英] How to force ASP.NET MVC to read .cshtml files as UTF-8?

查看:175
本文介绍了如何强制ASP.NET MVC以UTF-8格式读取.cshtml文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

渲染视图时,我遇到了编码问题,即unicode字符显示不正确.

When rendering a view, I encounter a problem with encoding, i.e. unicode characters are displayed incorrectly.

根据一个不相关的问题的答案:

如果您在输出中遇到编码问题,请尝试将视图.aspx文件另存为带签名的Unicode UTF-8".

If you experience encoding problems with the output, try saving your view .aspx files as 'Unicode UTF-8 with signature'.

实际上,我的视图已保存为 UTF-8(没有签名);将它们另存为带有签名的 UTF-8 即可解决此问题.

Indeed, my views were saved as UTF-8 without signature; saving them as UTF-8 with signature solves the problem.

是否有一种方法可以向ASP.NET MVC指定每次应使用UTF-8,以便能够对新存储的视图使用没有签名的UTF-8?

Is there a way to specify to ASP.NET MVC that it should use UTF-8 every time, in order to be able to use UTF-8 without signature for the newly stored views?

推荐答案

尝试:

<system.web>
    <globalization fileEncoding="utf-8" />
</system.web>

别忘了将源文件也保存在UTF-8中.

Don't forget to save your source file in UTF-8 as well.

这篇关于如何强制ASP.NET MVC以UTF-8格式读取.cshtml文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆