MaciekAiR
MaciekAiR

Reputation: 81

Special characters in UTF-8 using RenderBody()

I'm developing site in ASP.NET MVC6 with Polish letters. They work just fine when I write them in _Layout.cshtml, but I'm also using RenderBody() for rendering views.

Using Html.DisplayFor(modelItem => item.ID) inside view, displays Polish characters properly, but when I use plain html and write something, all I see on the website is "?" in place of every used Polish letter.

In _layout.cshtml I have a declaration:

<meta charset="utf-8" />

And in web.config I have:

<?xml version="1.0" encoding="utf-8"?>

Upvotes: 4

Views: 6654

Answers (2)

user3102567
user3102567

Reputation: 133

I have the same problem with asp.net core aka MVC6, visual studio 2017. Especial characters like â appear � and client side validation like ViewBag.Equals("â") is not working properly.

So I change the view files (.cshtml ) codification with notepad++ from ANSI to UTF-8.

enter image description here

Upvotes: 5

MaciekAiR
MaciekAiR

Reputation: 81

I checked my global solution settings for UTF-8, but I didn't checked single file encoding setting, so in solution explorer you have to click your .cshtml file, then:

file->advanced safe options->Unicode(UTF-8 with signature)-Codepage 65001

Now it works.

Upvotes: 4

Related Questions