0

I have my database results (áéíóúàâêô...) and when I display any of this characters I get codes like:

á 

My controller is like this:

ViewBag.EstadosDeAlma = (from e in db.EstadosDeAlma select e.Title).ToList();

My cshtml page is like this:

var data = '@foreach (dynamic item in ViewBag.EstadosDeAlma){ @(item + " ") }';

In addition, if I use any rich text editor as Tiny MCE all non-latin characters are like this too.

What should I do to avoid this problem?

Rubia Gardini
  • 815
  • 5
  • 16
  • 30
  • á is the correct encoding for the accented a character, and it should render OK on the page. Are you seeing the á on the page rendered to the user or when you view source in your browser? – Hector Correa Nov 06 '11 at 22:39
  • I´m using that with jquery autocomplete, so when I try to find the portuguese word "ágil" I can´t, cuz actually is written ágil in the html code... – Rubia Gardini Nov 07 '11 at 17:23

2 Answers2

0

What output encoding are you using on your web pages? I would suggest using UTF-8 since you want a lot of non-ascii characters to work.

Erik A. Brandstadmoen
  • 10,430
  • 2
  • 37
  • 55
  • Yes. That would be in you "master page" (Layout file, viewstart, etc, I don't know where you have your HTML head section). And of course you need to ensure that the characters are returned correctly from the database to your .net app too... – Erik A. Brandstadmoen Nov 07 '11 at 06:51
0

I think you should HTML encode/decode the values before comparing them.

Since you are using jQuery you can take advantage of the encoding functions built-in into it. For example:

$('<div/>').html('& #225;gil').html() 

gives you "ágil" (notice that I added an extra space between the & and the # so that stackoverflow does not encode it, you won't need it)

This other question has more information about this. HTML-encoding lost when attribute read from input field

Community
  • 1
  • 1
Hector Correa
  • 26,290
  • 8
  • 57
  • 73