Search code examples
javascriptjqueryrazorrazorengine

jQuery .dialog method fails when trying to set a title with accents


I want to modify at runtime an html page title, I am using the RazonEngineProcessor with a cshtml template based in a widged built with jQuery. The title is changed this way:

$("#ValDlgTitle").dialog('option', 'title', '@ViewBag.Model.Title');

I have found that, if the title has accents, the world is not shown correctly, for example, it says Mensajes de Validación instead of Mensajes de Validación.

The template also builds some dynamic tables by passing values from the ViewBag and in that case accents are shown correctly, for example this line:

<tr><td><span style="color:#f78955">@valWarn.SeverityLabel:&nbsp;&nbsp;@valWarn.TaskName&nbsp;-&nbsp;@valWarn.ValidationComment</span></td></tr>

Can become:

Aviso:  Solicitud (Dirección-General) - Campo de búsqueda nulo

Is there any way to change the title to some string with accents?


Solution

  • The problem is fixed by using .html instead of .dialog.

    $("#ValDlgTitle").html('@ViewBag.Model.Title');
    

    Another way this can be done is by referencing the title CSS class instead of referencing an Id.

    $(".ui-dialog-titlebar .ui-dialog-title").html('@ViewBag.Model.Title');