开发者

store and display html tags in MVC

How can I store post.content as html in database and how can I display with rendered html without tags. I am trying with following way, but it's not working. It can stored encode html in database but its not displayed rendered html. Any best practice would be开发者_运维知识库 appreciated.

1) //Saving post content in database as html

public ActionResult Edit(Post post, FormCollection obj)
        {               
          post.Content = Server.HtmlEncode(post.Content);
        }

2) //Displaying post content to view

<%: System.Web.HttpUtility.HtmlDecode(item.Content)%>

OR

<%: item.Content%>


MVC3/Razor:

@Html.Raw(item.Content)

MVC2/WebForms:

<%: MvcHtmlString.Create(item.Content) %>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜