Click here to Skip to main content
15,918,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a script tag like below in my partial view :
<script>
$(function () {
    $.ajax({
        type: "GET",
        url: "/api/ChartsAPI/2",
        dataType: "json",
        success: function (seriesData) {

            console.log(seriesData);

            $("#chart").kendoChart({
                dataSource: {
                    data: seriesData
                },
                series: [{
                    field: "yaxisData",
                    name: "Average"
                }],
                title:
                   { @ViewBag.PlaceHolder }
            });
        }
    });
})
</script>


In my controller the view bag data is populated like below :
ViewBag.PlaceHolder = "text:'test'";


But with this configuration, the chart is not getting rendered correctly as the chart text for the title is being rendered as below :

text:&#39;test&#39;


How to get rid of the ascii for the qutoes in javascript.
Posted

Use this:

@Html.Raw(ViewBag.PlaceHolder)
 
Share this answer
 
In JSON string quote (') has special meaning, so it got encoded to distinguish between quote as separator and quote as data...
You can escape quote (\'), which do work, but not comfort to the JSON specification...
What you should do according the specification is using an escaped double-quote (\")...
C#
ViewBag.PlaceHolder = "text:\"test\"";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900