jquery changes quotation mark to &quot after string injection in MVC

120 Views Asked by At

I'm making some tooltip customization of DevExtreeme chart and I want to inject the string into js code in MVC project:

.Tooltip(t => t
    .Enabled(true)
    .Location(Model.Tooltip.Location)
    .CustomizeTooltip(@<text>
function(arg) {
return {
text: @Model.Tooltip.Text 
};
}
    </text>)
)

The string looks like this:

Text = "arg.seriesName + \" years: \" + arg.valueText"

but on the output it is:

text: arg.seriesName +&quot; years: &quot; + arg.valueText 

How to fix that? (& didn't help)

Thanks for your help

2

There are 2 best solutions below

0
On BEST ANSWER

I have all the information which define the chart in the model. Here is the solution how it should be implemented:

Tooltip = new TooltipDataPackage
            {
                Enabled = true,
                Location = ChartTooltipLocation.Edge,
                Text = (item) =>
                {
                    var func = "function(arg) {";
                    func += "return {";
                    func += "text: arg.seriesName + \" wiek: \" + arg.valueText";
                    func += "};";
                    func += "}";
                    return MvcHtmlString.Create(func);
                }
            },

The object TooltipDataPackage code is defined as follows:

public class TooltipDataPackage
{
    public bool Enabled { get; set; }
    public RazorBlock Text { get; set; }
    public ChartTooltipLocation Location { get; set; }


}
0
On

It looks strange you keep custom tooltip text within a model. This string arg.seriesName + \" years: \" + arg.valueText isn't a common string. It's a JavaScript statement that calculates a string. So, it should not come from a model. Look at this sample:

.CustomizeTooltip(@<text>
   function (arg) {
      return {
         text: arg.argumentText + "<br />" + arg.valueText
     };
}
</text>)

Try to go the same way.