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

后端 未结 7 1503
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  梦毁少年i
    2021-02-06 22:57

    Well, to summarize.. In my service/Controller, while returning the model to the view

        ....
        Description = WebUtility.HtmlDecode(narration.Narration1)
    

    My cshtml, where the tinyMCE is displayed.. just bind regularly (I was using HtmlAttributeHelper for other purpose. You can ignore it)

     
    @Html.TextAreaFor(model => model.Description, HtmlAttributeHelper.ConditionalDisable(false, new {@class = "tinymce"}))

    And in the cshtml page where the data is displayed..

     ......
     @Html.Raw(HttpUtility.HtmlDecode(@item.Narration1))
    

提交回复
热议问题