Accent with Javascript Resource

Asked

Viewed 861 times

1

I have an Asp.Net MVC project where I use Source, but I’m having problems with accentuating other special characters.
Example:
I have the following Resource:

Name                   |  Value
MSG_SESSAO_EXPIRADA    |  *Sessão expirada!

In my View I have:

<script type="text/javascript" charset="utf-8">
      alert('@Resources.MSG_SESSAO_EXPIRADA');
</script>

The obtained is:

Sess&#227;o expirada!

I mean, he can’t display the ã, but does the conversion.
Could someone help me?

2 answers

1

Your html code has charset="utf-8". Your Resource file must be in UTF-8 format as well, otherwise it can give divergence in the charset.

An alternative is to write your Resource, converting the required characters using the character ratio in the Unicode/UTF8 table

Example: In place of ã write \u00E3

  • Well, this has only happened by putting Resource directly into Javascript, but when I use it in HTML it works perfectly.

1


I managed using an interesting alternative:
In my alert I used the method Raw of HTML Helper and worked perfectly.

alert('@Html.Raw(Resources.MSG_SESSAO_EXPIRADA)');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.