Fdr
Fdr

Reputation: 3714

How to avoid html encoding of strings in partial view

My goal is to separate js controls into partial views and parametrize them through ViewData. I want to pass a string in ViewData that is used as javascript string value.

Now the problem is that I don't know how to render a string that is not html encoded.

My current attempt is:

var domAsString = "<%: HttpUtility.HtmlDecode((string)ViewData["domLayout"]) %>"

Which renders it as a html-encoded string. How can I avoid this?

Upvotes: 1

Views: 1085

Answers (1)

Neil Fenwick
Neil Fenwick

Reputation: 6184

You could try:

var domAsString = "<%= (string)ViewData["domLayout"] %>"

The <%: %> syntax is shorthand for <%= Html.Encode( .... ) %>

Upvotes: 1

Related Questions