How to display HTML stored in a database from an ASP.NET MVC view?

前端 未结 3 1603
粉色の甜心
粉色の甜心 2020-12-14 01:22

I have HTML code emitted by FCKEditor stored in a database and would like to display (well render) it onto a view. So, for instance, something stored as:

&am         


        
相关标签:
3条回答
  • 2020-12-14 01:22

    you want to use @Html.Raw(str)

    See MSDN for more

    Returns markup that is not HTML encoded.

    This method wraps HTML markup using the IHtmlString class, which renders unencoded HTML.

    0 讨论(0)
  • 2020-12-14 01:38

    try

    <%= System.Web.HttpUtility.HtmlDecode(yourEncodedHtmlFromYouDatabase) %>
    

    more info here @ MSDN online.

    hth!

    0 讨论(0)
  • 2020-12-14 01:38

    The answer provided by Pure.Krome is flawless for MVC2, but consider Razor syntax:

    @Html.Raw(System.Web.HttpUtility.HtmlDecode(Model.yourEncodedHtmlFromYourDatabase))
    

    Alternatively,

    @Html.Raw(Server.HtmlDecode(Model.yourEncodedHtmlFromYourDatabase))
    
    0 讨论(0)
提交回复
热议问题