Display encoded html with razor
Use Html.Raw()
. Phil Haack posted a nice syntax guide at http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx.
<div class='content'>
@Html.Raw( Model.Content )
</div>
this is pretty simple:
HttpUtility.HtmlDecode(Model.Content)
Another Solution, you could also return a HTMLString, Razor will output the correct formatting:
in the view itself:
@Html.GetSomeHtml()
in controller:
public static HtmlString GetSomeHtml()
{
var Data = "abc<br/>123";
return new HtmlString(Data);
}
You can also simply use the HtmlString
class
@(new HtmlString(Model.Content))
Try this:
<div class='content'>
@Html.Raw(HttpUtility.HtmlDecode(Model.Content))
</div>