开发者

ASP.NET MVC how to display html tags as html?

I display some text in the view:

....
 <%: model.Content %>
....

my model.Content contains html tags, and I want to display开发者_StackOverflow社区 them not as text, but as html. How to do it?

Thanks.


As of MVC 3 you can use:

@Html.Raw(model.Content)


<%= model.Content %>

Be careful with this because it could open your site to XSS attacks.


Use:

<%: MvcHtmlString.Create(model.Content) %>

or

<%= model.Content %>

Because <%: does Html encoding, while <%= doesn't.

MvcHtmlString.Create creates a 'save' Html string, which<%: takes and prints out as is.


<%= Model.Content %>

The colon : is short for Html.Encode() while equal = simply post what is in the string.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜