Traffy
Traffy

Reputation: 2861

ASP.NET MVC - French accent not correctly displayed in popup window

I'm working with ASP.NET MVC and I'm trying to display a success (or error) message through a popup window. My message contains some french accents and there are not correctly displayed. For instance, instead of displaying "é", I got "&#233" in place. I've put these line in my part but nothing changes :

I also tried to replace my accents by the "code" but it is also not working.

Here's what I'm doing:

In my controller:

TempData["Message"] = "Rendez-vous enregistré avec succès";
return RedirectToAction("NewAppointment");

In my View (NewAppointment):

@{
    var message = TempData["Message"] ?? string.Empty;
}

<script type="text/javascript">
    var message = '@message';
    if (message)
        alert(message);
</script>

Any way to get my accents correctly displayed?

Upvotes: 0

Views: 2312

Answers (3)

Use this

<script type="text/javascript">
var message = '@Html.Raw(message)';
if (message)
    alert(message);
</script>

Upvotes: 0

Menno van den Heuvel
Menno van den Heuvel

Reputation: 1861

Your string automatically gets html encoded. Prevent that by using Html.Raw():

var message = '@Html.Raw(message)';

Upvotes: 1

Perfect28
Perfect28

Reputation: 11317

Use MvcHtmlString to avoid razor for htmlencoding your string :

 var message = '@(new MvcHtmlString(message))' ; 

Upvotes: 1

Related Questions