Pergunta

Ok, so I hava this C# POCO class, and some of it's properties may be assigned a string containing non-english characters, like "ç" and "õ".

In my Controller class I got this:

public ActionResult GetBuildStages()
{
    var buildStages = SubcategoriesViewModel.GetBuildStages();

    return Json(buildStages, JsonRequestBehavior.AllowGet);
}

And when I load the resulting JSON in my view (javascript), using $.getJSON, those characters mentioned above, for example, will show as "&#231", for "ç", and "&#245", for "õ"

Any thoughts on how to correctly serialize those characters some javascript can work with them would be greatly appreciated.

Foi útil?

Solução

I believe you can allow .NET to do its thing and just use Javascript and the browser to decode the characters (or everything) if that is what you need. The following stack question addresses how to do this with just javascript: Decode & back to & in JavaScript. Based on that you would probably be looking at something like:

var div = document.createElement('div');
div.innerHTML = encoded;
var decoded = div.firstChild.nodeValue;

Hope that helps!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top