视图中的重音字符未正确呈现

Ren*_*uis 4 .net unicode razor servicestack

我使用ServiceStack(v3.9.44.0)作为Windows服务(目标是.Net4.5),我使用Razor让ServiceStack生成并提供HTML.

事情很好,但有一个奇怪的问题:看起来视图.cshtml中硬编码的unicode字符串没有正确呈现.
这就是我的意思:

视图中的重音符号未正确呈现

项目视图的结构是规范的:

查看项目结构

随着_Layout.cshtml:

<!doctype html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    </head>
    <body>
        <p>Accents in \Views\_Layout.cshtml: à é ë ô</p>

        @RenderBody()
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

并且Articles.cshtml:

@inherits ViewPage<List<PrepaService.Article>>

<p>Accents in \Views\Articles.cshtml: à é ë ô</p>

Table with code-injected list of items:
<table>
    @foreach(var a in Model) {
        <tr>
            <td>@a.Description</td>
        </tr>
    }
</table>
Run Code Online (Sandbox Code Playgroud)

这两个文件都正确保存为无BOM的UTF8文件.

我也尝试添加以下内容,但它不会改变任何内容:

SetConfig(new EndpointHostConfig {
    AppendUtf8CharsetOnContentTypes = new HashSet<string> { ContentType.Html }
});
Run Code Online (Sandbox Code Playgroud)

所以,回顾一下:

  • 我对所有文件和显式charset=utf-8内容类型定义使用无BOM的UTF8编码.

  • 这适用于渲染的任何内容_Layout.cshtml,以及View模板中代码注入的任何内容

  • 但它不适用于View模板中的硬编码字符串.

参考文献:

Ren*_*uis 6

好的,回答我自己的问题,万一有人偶然发现类似的问题:

  • Razor似乎要求所有文件都是带有 BOM的UTF8 .

我被其中一个参考文献显然误导了但是找到了类似问题的答案.

它现在正常工作.


归档时间:

查看次数:

1280 次

最近记录:

12 年,6 月 前