Search code examples
htmlasp.net-mvcasp.net-mvc-3c#-4.0razor

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


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 HTML content as DECODED.

How shall I change my code in the View?

 <div class="display-field">
        @Html.DisplayFor(model => model.ContentBody)
 </div>

Solution

  • <div class="display-field">
        @Html.Raw(Model.ContentBody)
    </div>
    

    This code solved the problem!