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.
加载中,请稍侯......
精彩评论