Accented characters in views do not display properly

I use ServiceStack (v3.9.44.0) as a Windows service (targeting .Net4.5) and I use Razor so that ServiceStack generates and serves HTML.

Everything works very well, but there is a strange problem: it seems that the hardcoded unicode lines in the .cshtml view .cshtml not displaying properly.
Here is what I mean:

Accents in Views are not rendered properly

The structure of project representations is canonical:

Views project structure

From _Layout.cshtml is:

 <!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> 

and 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> 

Both files are correctly saved as UTF8 files containing no data.

I also tried adding the following, but didn't change anything:

 SetConfig(new EndpointHostConfig { AppendUtf8CharsetOnContentTypes = new HashSet<string> { ContentType.Html } }); 

So, to do the following:

  • I use BOM-less UTF8 encoding for all files and explicitly determine the content type charset=utf-8 .

  • this works for everything that is displayed in _Layout.cshtml and everything that is entered by the code inside the viewing templates

  • but does not work for hard-coded strings in view templates .

References:

+4
source share
1 answer

Well, answering my question if someone stumbles on a similar problem:

  • Razor seems to require all files to be UTF8 with specification.

I was misled by one of the links, but found the answer to a similar question .

Now it works correctly.

+6
source

Source: https://habr.com/ru/post/1479841/


All Articles