I store encoded HTML in the database.
The only way i could display it correctly is :
<div class='content'>
@MvcHtmlString.Create(HttpUtility.HtmlDecode(Model.Content));
</div>
It's ugly. Is there any better way to do this?
I store encoded HTML in the database.
The only way i could display it correctly is :
<div class='content'>
@MvcHtmlString.Create(HttpUtility.HtmlDecode(Model.Content));
</div>
It's ugly. Is there any better way to do this?
this is pretty simple:
Another Solution, you could also return a HTMLString, Razor will output the correct formatting:
in the view itself:
in controller:
You can also simply use the
HtmlString
classUse
Html.Raw()
. Phil Haack posted a nice syntax guide at http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx.Imho you should not store your data html-encoded in the database. Just store in plain text (not encoded) and just display your data like this and your html will be automatically encoded:
Try this: