开发者

store and display html tags in MVC

开发者 https://www.devze.com 2023-02-14 19:04 出处:网络
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 htmlin database but

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

精彩评论

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