存储和显示的HTML标签的MVC [英] store and display html tags in MVC
本文介绍了存储和显示的HTML标签的MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能存储post.content为HTML数据库,以及如何我可以呈现的HTML显示没有标签。我用下面的方式尝试,但它不工作。它可以存储连接数据库code HTML,但它不显示呈现的HTML。任何最好的做法是AP preciated。
1)
在数据库//保存帖子内容为HTML
公众的ActionResult编辑(后后,的FormCollection OBJ)
{
post.Content = Server.HtmlEn code(post.Content);
}
2)
//显示帖子的内容,查看
<%:System.Web.HttpUtility.HtmlDe code(item.Content)%GT;
或
<%:item.Content%GT;
解决方案
MVC3 /剃须刀:
@ Html.Raw(item.Content)
MVC2 / WebForms的:
<%:MvcHtmlString.Create(item.Content)%GT;
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) %>
这篇关于存储和显示的HTML标签的MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文