vernou
vernou

Reputation: 7590

Special characters in Razor template not being encoded correctly

I make some test with ASP.NET Core MVC. I am trying to display special character like çùé.

But it is displayed as �.

Exemple :

Create new view and put :

<div>àçù</div>

By default, the .cshtml file is encoded in "UTF-16". The charset in HTTP response header is "UTF-8". In _layout, the <head> contains the <meta charset="utf-8" /> tag.

To resolve the problem, I can convert all .cshtml file to uft-8.

What's the correct way to manage encodage in ASP MVC Core?

Edit :

Visual Studio 2017 RC create .cshtml file in 'utf-8', but the scaffolding create the .cshtml file in 'ISO 8851-1'.

Can I explain to scaffolding I want .cshtml file in 'UTF-8'?

Upvotes: 14

Views: 11010

Answers (2)

Savo Pejović
Savo Pejović

Reputation: 153

What did it for me is copying the view's content into Notepad++, deleting the file, adding it anew, and pasting the saved content.

Upvotes: 1

Ricker Silva
Ricker Silva

Reputation: 1135

I solved it by simply opening the file with problems, confirming it was encoded as ANSI, converted it to UTF-8 and everything run smooth again. I also created a post for this, so both seem duplicated right now. MVC .net core is not displaying special characters correctly

Upvotes: 4

Related Questions