Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

encoding - How to force ASP.NET MVC to read .cshtml files as UTF-8?

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

According to an answer to an unrelated question:

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

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...