在MVC中存储和显示html标签

Hid*_*man 2 asp.net-mvc asp.net-mvc-3 asp.net-mvc-2

如何将post.content存储为数据库中的html,如何在没有标签的情况下显示渲染的html.我正在尝试以下方式,但它不起作用.它可以在数据库中存储编码html但不显示渲染的html.任何最佳实践将不胜感激.

1)//将数据库中的帖子内容保存为html

public ActionResult Edit(Post post, FormCollection obj)
        {               
          post.Content = Server.HtmlEncode(post.Content);
        }
Run Code Online (Sandbox Code Playgroud)

2)//显示要查看的帖子内容

<%: System.Web.HttpUtility.HtmlDecode(item.Content)%>
Run Code Online (Sandbox Code Playgroud)

要么

<%: item.Content%>
Run Code Online (Sandbox Code Playgroud)

Jam*_*s H 5

MVC3 /剃刀:

@Html.Raw(item.Content)
Run Code Online (Sandbox Code Playgroud)

MVC2/WebForms的:

<%: MvcHtmlString.Create(item.Content) %>
Run Code Online (Sandbox Code Playgroud)