开发者

How to avoid html encoding of strings in partial view

开发者 https://www.devze.com 2023-03-29 03:55 出处:网络
My goal is to separate js controls into partial views and parametrize them through ViewData. I want to pass a string in ViewData th开发者_运维技巧at is used as javascript string value.

My goal is to separate js controls into partial views and parametrize them through ViewData. I want to pass a string in ViewData th开发者_运维技巧at 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?


You could try:

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消