1

I am working on a asp.net mvc5 project and I just noticed it doesn't allow me to use 'åäö' well it allows me to use these characters but it shows up like this. 'ä' and so on.

The weird thing I can use the characters in my nav bar but on a page it won't allow it.

This is my login page:

Login Page

It should say "Användarnamn" and "Lösenord".

But it my navbar it works correctly..

enter image description here

this is my shared _Layout every site inherits from

<!DOCTYPE html>
<html lang="sv">
<head>
    <title>Treetop @ViewBag.Title</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/modernizr")
    <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css"/>
</head>
<body>
    @if (User.Identity.IsAuthenticated)
    {
        <div class="page-header">
            <div class="page-header-top">
                <div class="container">
                    <div class="page-logo">
                        <h3>Treetop Innovation</h3>
                    </div>
                    <a href="javascript:;" class="menu-toggler"></a>
                </div>
            </div>
            <div class="page-header-menu">
                <div class="container">
                    <div class="hor-menu ">
                        <ul class="nav navbar-nav">
                            <li>
                                @Html.ActionLink("Ny Rapport", "TimeReport", "Reports")
                            </li>
                            <li>
                                @Html.ActionLink("Rappotera frånvaro", "Absent", "Reports")
                            </li>
                            <li>
                                @Html.ActionLink("Rapporter", "Index", "Reports")
                            </li>
                            <li>
                                @Html.ActionLink("Inställningar", "Settings", "Reports")
                            </li>
                            <li>
                                @Html.ActionLink("Mina projekt", "Index", "Projects")
                            </li>
                            <li>
                                @Html.ActionLink("Begär semester", "Index", "Vacation")
                            </li>
                        </ul>
                    </div>
                    <div class=" hor-menu nav navbar-nav pull-right">
                        <ul class="nav navbar-nav">
                            <li><a>@User.Identity.Name</a></li>
                            <li>
                                @using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" }))
                                {
                                    @Html.AntiForgeryToken()
                                    <a href="javascript:document.getElementById('logoutForm').submit()">Log off</a>
                                }
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <script>
            jQuery(document).ready(function () {
                Metronic.init();
                Layout.init();
                Demo.init();
                ComponentsPickers.init();
                TableAdvanced.init();
            });
        </script>
    }
    @RenderBody()
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/modernizr")
    @RenderSection("scripts", required: false)
</body>
</html>

This is the view that does not work:

<body class="login">
    <div class="logo">
        <h3 style="color: white">Treetop Innovation</h3>
    </div>
    <div class="content">
        @using (Html.BeginForm("LogOn", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "login-form", role = "form" }))
        {
            @Html.AntiForgeryToken()
            <div class="alert alert-danger display-hide">
                <button class="close" data-close="alert"></button>
                <span>
                    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                </span>
            </div>
            <h3 class="form-title">Logga in</h3>
            <div class="form-group">
                <div class="input-icon">
                    <i class="fa fa-user"></i>
                    @Html.TextBoxFor(m => m.UserName, new { @class = "form-control", placeholder = "Användarnamn" })
                </div>
                @Html.ValidationMessageFor(m => m.UserName, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <div class="input-icon">
                    <i class="fa fa-lock"></i>
                    @Html.PasswordFor(m => m.Password, new { @class = "form-control", placeholder = "Lösenord" })
                </div>
                @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
            </div>

            <div class="form-actions">
                <div class="checkbox" style="padding: 0 20px">
                    @Html.CheckBoxFor(m => m.RememberMe)
                    Kom ihåg
                </div>
                <button type="submit" class="btn green-haze pull-right">
                    Login <i class="fa fa-arrow-right"></i>
                </button>
            </div>
        }
    </div>
</body>
Joakim Carlsson
  • 1,540
  • 5
  • 19
  • 42

2 Answers2

0

This is basically a encoding issue. read more There Ain't No Such Thing as Plain Text

Användarnamn = Anv&#228;ndarnamn 

and

Lösenord = L&#246;senord

You can use HTML Entities or ISO Latin-1 code for these special characters.

https://www.utexas.edu/learn/html/spchar.html

UPDATE @Broam's answer which solved the issue

Short version: edit one file, select File -> Advanced Save Options. Instead of changing UTF-8 to Ascii, change it to UTF-8. Edit: Make sure you select the option that says no byte-order-marker (BOM)

Community
  • 1
  • 1
Sandeep Kumar M
  • 3,841
  • 3
  • 38
  • 59
  • But there must be a way to fix this as it works in the Navbar but not on the page.. ? And this is how i get my value. @Html.TextBoxFor(m => m.UserName, new { @class = "form-control", placeholder = "Användarnamn" }) so with your solution it only made it worse. – Joakim Carlsson Aug 04 '15 at 07:33
0

You have to save the .cshtml file with the right Encoding.

  1. File > Save MyFile.cshtml As...

  2. Chose Save with Encoding...

  3. Chose Yes to replace it.

  4. Chose UTF-8.

enter image description here

enter image description here

Joel Wiklund
  • 1,697
  • 2
  • 18
  • 24