0

My problem is that the words that are returned from my controller to view via JsonResult are losing their accent, instead of accent it's getting converted for a symbol.

This word "Finalizar_Saída" is been wrong rendered this way = "Finalizar_Sa�da".

My initial return call:

return Json(Object);

I Already tried things like this:

Add in HTML page:
< META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="@Url.Content("~/path/fileName.js")" type="text/javascript" charset="utf-8"></script> 

Add in document javascript:

contentType: "application/json; charset=ISO-8859-1",
dataType: "json",

Add in web.config this text:

<globalization culture="pt-BR" uiCulture="pt-BR" requestEncoding="iso-8859-1" responseEncoding="iso-8859-1" fileEncoding="iso-8859-1" />

or

<globalization enableClientBasedCulture="false" requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="utf-8"
      responseHeaderEncoding="utf-8"  enableBestFitResponseEncoding="true" culture="es-MX" uiCulture="es-MX"/>

Add in C# :

I've changed the return call like this:

Json(Object, "application/json", Encoding.UTF8); 

Do someone know a way to figure this out?

Raphael Ribeiro
  • 529
  • 5
  • 18
  • Why not to use utf-8 in contentType? or just remove charset=ISO-8859-1 from contentType property – apros Sep 22 '14 at 17:58

2 Answers2

0

This is a way, not necessarily a great way:

You can store the strings with the desired characters using the HTML encodings found

here

The names will likely no longer be human-readable in the code/DB, but should display correctly in a browser. You could conceivably parse the strings in a UTF-aware language and use its native encoding/decoding functions combined with a regex to replace the unicode characters with the HTML codes, this could even be done on the fly before sending to the client AJAX request.

Jared Smith
  • 19,721
  • 5
  • 45
  • 83
0

I'm sorry, the problem wasn't the way to render the text but the way i was reading informations.

I was reading the information from a file which in our case was a file generated by log4net.

The problem is that log4net was writing in ansi standard and we thought that it was utf8 standard,

The solution was change the read mode to ansi standard using the following call:

Encoding.Default.GetString(buffer).

Now it's working.

Anyway thanks.

Raphael Ribeiro
  • 529
  • 5
  • 18