16

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?

2 Answers 2

32

Try:

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

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

Sign up to request clarification or add additional context in comments.

Comments

3

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" />

1 Comment

The problem occurs before IIS, since the encoding is already wrong in the HTML string I generate from the view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.