问题
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?
回答1:
Your string automatically gets html encoded. Prevent that by using Html.Raw():
var message = '@Html.Raw(message)';
回答2:
Use MvcHtmlString to avoid razor for htmlencoding your string :
var message = '@(new MvcHtmlString(message))' ;
回答3:
Use this
<script type="text/javascript">
var message = '@Html.Raw(message)';
if (message)
alert(message);
</script>
来源:https://stackoverflow.com/questions/24570473/asp-net-mvc-french-accent-not-correctly-displayed-in-popup-window