问题
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%>
回答1:
MVC3/Razor:
@Html.Raw(item.Content)
MVC2/WebForms:
<%: MvcHtmlString.Create(item.Content) %>
来源:https://stackoverflow.com/questions/5202218/store-and-display-html-tags-in-mvc