I put <meta http-equiv="content-type" content="text/html; charset=utf-8" />
in the head, and DOCTYPE at the top of my _Layout.cshtml
, but still when I'm viewing the website, the special Turkish characters are displayed as like '1; and such in the source, not in the page. The webpage displays them correctly, the source file has the problem..
Do you know what else I should do to correct this?
Try to save your source file as UTF-8 with BOM.
I was having a similar issue and it seems that Razor expects files to have the BOM signature.
In Visual Studio: FILE > Advanced Save Options:
I had exactly the same problem, tried all the solutions and none of them worked, checked .cshtml file encoding with Notepad++ and it was correct (utf8 with BOM), SaveAs file with encoding (as shown above) but the problem still persisted.
Finally I found out that there was nothing wrong with my razor files, it seems that ASP.Net core MVC does not set UTF-8 encoding as default encoding and it must be set if needed by developer.
I added the below code at the end of ConfigureServices
method of Program.cs
(it adds UTF-8 encoding to default encodings) and the problem solved.
services.AddWebEncoders(o => {
o.TextEncoderSettings = new System.Text.Encodings.Web.TextEncoderSettings(UnicodeRanges.All);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With