问题
I have ASP.NET MVC 3 application having resource files in english and french. A text 'Sélectionner la pharmacie' is stored in a french resource file.
When the value is read from resource files with razor syntax, it shows 'S#233;lectionner la pharmacie' instead of 'Sélectionner la pharmacie'.
e.g.
@MyResources.Strings_Resources.lbl_SelectPharmacy
Is there a way I can make it show the french accent characters ?
回答1:
I suspect that your text is already encoded and razor is trying to encode it again (it encodes all outputs)
Try with
@Html.Raw(MyResources.Strings_Resources.lbl_SelectPharmacy)
回答2:
First check your master page, you have set UTF-8
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<system.web>
<globalization enableclientbasedculture="true" uiculture="auto" culture="auto">
<!-- Use above or below <globalization> line, based on your site -->
<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8"/>
</system.web>
If you have set this already then try below setup:-
<asp:Label Text="<%$ Resources:Strings, MyGlobalResource %>" runat="server" />
<asp:Label Text="<%$ Resources:MyLocalResource %>" runat="server" />
<%= HttpContext.Current.GetLocalResourceString("~/YOURASPXPAGE", "MyLocalResource", CultureInfo.CurrentUICulture) %>
Refer this URL for more info:-
- ASP.NET MVC 3 Internationalization
- ASP.NET MVC - Localization Helpers
来源:https://stackoverflow.com/questions/8180123/asp-net-mvc-3-jquery-french-accent-characters-are-showing-as-233-characters-o