You need to use %=
instead of %:
<%= ViewBag.Chart %>
if you are using %:
it is automatically HTML encodes your string while the %=
does not.
Sidenote: it is not a good practice to emit JavaScript from your controller into your view...
Frage
I am using ASP.NET MVC 4 with aspx.
I want from my controller to produce code at my view.
Therefore I have a line at my controller which is
ViewBag.Chart = "var c = r.barchart(10, 10, 600, 440, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]], { stacked: true, type: \"soft\" }).hoverColumn(fin2, fout2);";
However, when it shows at my code, it does not shows the character (") but instead it replaces it with a & quot;
What I can do in order to produce the character " at the code?
Lösung
You need to use %=
instead of %:
<%= ViewBag.Chart %>
if you are using %:
it is automatically HTML encodes your string while the %=
does not.
Sidenote: it is not a good practice to emit JavaScript from your controller into your view...
Andere Tipps
Hi try placing \ in front of the quote and before closing the quotes. It works fine for me
\"var c = r.barchart(10, 10, 600, 440, [[55, 20, 13, 32, 5, 1, 2, 10], [10, 2, 1, 5, 32, 13, 20, 55]], { stacked: true, type: \"soft\" }).hoverColumn(fin2, fout2);\";