How to tell razor NOT to html escape

Javascriptasp.net Mvc-3Razor

Javascript Problem Overview


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

Javascript Solutions


Solution 1 - Javascript

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

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

Solution 2 - Javascript

If you have done everything and still issue persist while it was working earlier.. Better check Certificate Expiration Date.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsTodorovView Question on Stackoverflow
Solution 1 - JavascriptSLaksView Answer on Stackoverflow
Solution 2 - JavascriptVikas ParikhView Answer on Stackoverflow