ASP.NET MVC 3 jquery : French accent characters are showing as #233 characters on screen
Asked Answered
S

3

10

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 ?

Supernatant answered 18/11, 2011 at 9:15 Comment(0)
R
12

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)
Rudimentary answered 18/11, 2011 at 12:27 Comment(1)
Most probably, this is not the case. There is no reason why somebody would store HTML-encoded data into resources. But ASP.NET’s default HTML encoder encodes (for reasons unknown to me) all characters between 160–256. See e.g. https://mcmap.net/q/1163567/-special-characters-in-html-output (and the question). Using Html.Raw is most often just a security hole waiting to happen.Haematite
M
4

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:-

  1. ASP.NET MVC 3 Internationalization
  2. ASP.NET MVC - Localization Helpers
Meanie answered 18/11, 2011 at 9:21 Comment(3)
I don't think the problem is the charset since the character is showed encoded, not gârbl€d™Rudimentary
Like Bettle Midler said, you are my hero!Squier
adding above line in<system.web> worked for me thanks a lot.<meta ...> was doing nothing.Scuba
S
0

I was having problem showing French characters in textarea through JQuery/Javascript (asp.net mvc).

myArry.push("\r\n" + "SÉRIE CERVICALE");
$('#myTextArea').val(myArry);

Result 🙁: SÉRIE CERVICALE

Adding this line in Web.config worked for me.

<system.web>
<globalization fileEncoding="utf-8" requestEncoding="utf-8"responseEncoding="utf-8"/>
</system.web>

Result 🙂: SÉRIE CERVICALE

Scuba answered 18/2, 2022 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.