I have HTML code edited by FCKEditor stored in a database and would like to display (well render) it onto a view. So, for instance, something stored as:
<>pre<>This is some sample text<>pre</>
Will be displayed to the user as:
This is some sample text
(With the appropriate style for pre-formatted-text)
The view already has the required string to display from ViewData
, I'm just not sure what the best way to show it to the user is.
There are two ways in MVC to create custom Html helpers as below. We can create our own HTML helper by writing extension method for HTML helper class. These helpers are available to Helper property of class and you can use then just like inbuilt helpers. Add new class in MVC application and give it meaningful name.
It is not mandatory to use HTML Helper classes for building an ASP.NET MVC application. We can build an ASP.NET MVC application without using them, but HTML Helpers helps in the rapid development of a view.
Try this:
<%= System.Web.HttpUtility.HtmlDecode(yourEncodedHtmlFromYouDatabase) %>
More info here.
The answer provided by Pure.Krome is flawless for MVC2, but consider Razor syntax:
@Html.Raw(System.Web.HttpUtility.HtmlDecode(Model.yourEncodedHtmlFromYourDatabase))
Alternatively,
@Html.Raw(Server.HtmlDecode(Model.yourEncodedHtmlFromYourDatabase))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With