Newbie1001
Newbie1001

Reputation: 161

ASP.NET MVC 5 application character encoding problem

I am currently developing an ASP.NET MVC 5 application, but I have issues with characters like "áéíöőúű" etc. The issue is in my _layout.cshtml.

The characters looks like are encoded like ISO-8859 characters, even though it is set to UTF-8.

For example: "applikáció" renders as "applikáciĂł"

What I already checked and tried:

  1. in _Layout.csthml, in the head section the character set is set to 'utf-8' properly
  2. In Visual Studio, in advanced save options shows the files are saved with UTF-8 character encoding.
  3. I also removed all scripts and css file reference from _Layout.cshtml, but problem persists
  4. In web.config, in the first row is is set the xml encoding to utf-8, so that should not caused the problem
  5. Tried to change font-family, but the problem still persist
  6. What strange is, the child views are working fine in @Renderbody, so I assume it was not about keyboard language settings

Here is the complete code I copied, navbar items, title and footer contains characters

 <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Applicatión</title>
    @using System.Configuration;

    @Styles.Render("~/Content/css")
        @Styles.Render("~/Content/fontawesome")

        @Scripts.Render("~/bundles/modernizr")
        @Styles.Render("~/Content/DevExtremeBundle")

        @Scripts.Render("~/bundles/jquery")
        @Scripts.Render("~/Scripts/DevExtremeBundle")

</head>
<body>
    <nav class="navbar navbar-expand-lg bg-light fixed-top">
        <div class="container-fluid">
            <a class="navbar-brand" href="#">Navbar</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
                <div class="navbar-nav">
                    <a class="nav-link active" aria-current="page" href="~/Home/Index">Főoldal</a>
                    <a class="nav-link" href="~/Jobs/Index">Munkák</a>
                    <a class="nav-link" href="~/EmailAddressGroup">Emailezés</a>
                </div>
            </div>
        </div>
    </nav>
    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p class="h6">&copy; @DateTime.Now.Year - My ASP.NET Application, applikáció</p>
        </footer>
    </div>
    @*<script src="~/Scripts/bootstrap.min.js"></script>*@


    @*@RenderSection("scripts", required: false)*@




</body>
</html>

The result enter image description here

I am out of ideas how to fix it, so any help appreciated.

Upvotes: 0

Views: 416

Answers (1)

Newbie1001
Newbie1001

Reputation: 161

In web.config, setting the globalization solves the problem.

Have to place following inside the system.web:

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

And it is fine.

Upvotes: 1

Related Questions