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

前端 未结 2 1677
栀梦
栀梦 2020-12-31 16:06

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:

相关标签:
2条回答
  • 2020-12-31 16:32

    I believe encoding is not the responsibility of MVC, rather IIS. Do you have this line in your web.config?

    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
    
    0 讨论(0)
  • 2020-12-31 16:58

    Try:

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

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

    0 讨论(0)
提交回复
热议问题