Razor模板中的特殊字符未正确编码 [英] Special characters in Razor template not being encoded correctly
问题描述
我使用ASP.NET Core MVC进行了一些测试. 我正在尝试显示çùé这样的特殊字符.
I make some test with ASP.NET Core MVC. I am trying to display special character like çùé.
但是它显示为 .
示例:
创建新视图并放置:
<div>àçù</div>
默认情况下,.cshtml
文件编码为"UTF-16".
HTTP响应标头中的字符集为"UTF-8".
在_layout中,<head>
包含<meta charset="utf-8" />
标记.
By default, the .cshtml
file is encoded in "UTF-16".
The charset in HTTP response header is "UTF-8".
In _layout, the <head>
contains the <meta charset="utf-8" />
tag.
要解决此问题,我可以将所有.cshtml文件转换为uft-8.
To resolve the problem, I can convert all .cshtml file to uft-8.
在ASP MVC Core中管理编码的正确方法是什么?
What's the correct way to manage encodage in ASP MVC Core?
Visual Studio 2017 RC在'utf-8'中创建.cshtml文件,但是脚手架在'ISO 8851-1'中创建.cshtml文件.
Visual Studio 2017 RC create .cshtml file in 'utf-8', but the scaffolding create the .cshtml file in 'ISO 8851-1'.
我可以向脚手架解释我要在'UTF-8'中使用.cshtml文件吗?
Can I explain to scaffolding I want .cshtml file in 'UTF-8'?
推荐答案
我通过简单地打开有问题的文件来解决它,确认文件已编码为ANSI,将其转换为UTF-8,一切再次恢复正常.我也为此创建了一个帖子,所以现在两者似乎都是重复的. MVC .net核心未正确显示特殊字符
I solved it by simply opening the file with problems, confirming it was encoded as ANSI, converted it to UTF-8 and everything run smooth again. I also created a post for this, so both seem duplicated right now. MVC .net core is not displaying special characters correctly
这篇关于Razor模板中的特殊字符未正确编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!