How to display encoded HTML as decoded in MVC 3 Razor?

后端 未结 7 1496
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 21:54

I\'m using Razor in MVC 3 and Asp.net C#.

I have a View with the following code. model.ContentBody has some HTML tags.

I would need display this HTM

相关标签:
7条回答
  • 2021-02-06 22:59

    Pass in "ContentBody" as MvcHtmlString to your model instead of a string.

    This way you can just use:

    <div class="display-field">
            @model.ContentBody
     </div>
    

    in your controller to get a MvcHtmlString just use:

    MvcHtmlString myHtmlString = MvcHtmlString.Create("htmlcodeandtext");
    
    0 讨论(0)
提交回复
热议问题