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

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

问题描述

渲染视图时,遇到编码问题,即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 将 .cshtml 文件读取为 UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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