Tuesday, June 4, 2024
143
rated 0 times [  149] [ 6]  / answers: 1 / hits: 21334  / 14 Years ago, thu, december 16, 2010, 12:00:00

I am using asp.net mvc 3 with razor for a project.
At some I need to serialize an array from the controller, put it in the viewdata and assign it to a js object. However when I output it using



@ViewData[some array]


The result is html escaped so i get something like :



[{"title":"Something","id":"Something-1" etc'


With the <%= %> this was not escaped so it was behaving as expected.
Is it possible to tell razor not to escape this string. Perhaps, someone might suggest another approach all together.



Thanks in advance for any ideas


More From » asp.net-mvc-3

 Answers
16

You need to output an instance of the new IHtmlString interface, which contains pre-escaped HTML.



To do that write @Html.Raw(...).


[#94574] Tuesday, December 14, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeremiahianx

Total Points: 629
Total Questions: 106
Total Answers: 112

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
;