Reputation: 2861
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 "é" 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
Reputation: 37
Use this
<script type="text/javascript">
var message = '@Html.Raw(message)';
if (message)
alert(message);
</script>
Upvotes: 0
Reputation: 1861
Your string automatically gets html encoded. Prevent that by using Html.Raw():
var message = '@Html.Raw(message)';
Upvotes: 1
Reputation: 11317
Use MvcHtmlString
to avoid razor for htmlencoding your string :
var message = '@(new MvcHtmlString(message))' ;
Upvotes: 1