3

When I display a chart and its title has an apostrophe, the title displays the ' as &#39.

How can I prevent this from happening?

user776676
  • 4,265
  • 13
  • 58
  • 77

2 Answers2

1
<script>
    var data = [];
    var labels = [];
    @foreach (var item in Model) {     
        @:labels.push("@Html.Raw(HttpUtility.JavaScriptStringEncode(item.TitleWithApostrophe))");
    }    
</script>

More about this question here: Javascript, Razor and Escape characters. Like apostrophe

Community
  • 1
  • 1
0

Have you copied the title from somewhere if so try copying into notepad first then into VS.

If not you may and you are generating it dynamically you may need to make sure you set the encoding on the chart (if there is a setting) to the source encoding

Daniel Powell
  • 8,143
  • 11
  • 61
  • 108
  • 1
    I think I see what you're suggesting, but note that hex 39 *is* the code for the standard ASCII apostrophe, rather than a 'smart quote' or anything like that. – AakashM Jun 25 '11 at 14:49