Search code examples
asp.net-mvcviewdata

Problems with accents in @html.Enconde(ViewData["Feedback"])


I'm having prolemas with accents when they step values ​​to ViewData.

In Controller:

ViewData["mensagem"] = "Não Esta Correto"

In View:

@Html.Encode(ViewData["mensagem"])

appears the : Não Esta Correto

Only the string that is passed by the ViewData have this problem, how to fix .


Solution

  • @ already encodes. This is the main diff between razor and aspx ... You are double encoding.

    @ViewData["mensagem"]
    

    To NOT encode:

    @Html.Raw(ViewData["mensagem"])