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

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

This code solved the problem!


You could also decode html in the controller before sending the model to the view,

WebUtility.HtmlDecode()

    public ActionResult Index(int id)
    {
        var content = _contentRepository.GetContent(id);
        var classViewModel = new ClassViewModel
                                 {
                                     ContentBody = WebUtility.HtmlDecode(ClassViewModel.ContentBody)
                                 };
        return View(classViewModel);
    }

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)

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

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

 ......
 <td class="col-word-wrap">@Html.Raw(HttpUtility.HtmlDecode(@item.Narration1))</td>

@Html.Raw was not work for me here is example:-

  string name = "&lt;p&gt;&lt;span style=&quot;font-size: small; color: #ff0000;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;span style=&quot;font-size: large; color: #000000;&quot;&gt;Hi&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &lt;br /&gt;This is just a sample,&lt;br /&gt;This will not work with @Html.Raw(),&lt;br /&gt;";
  <span>@Html.Raw(name);</span>

But this worked instead:-

@MvcHtmlString.Create(HttpUtility.HtmlDecode(@model.ContentBody))

or you can also use :-

@Html.Raw(HttpUtility.HtmlDecode(@model.ContentBody));