Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode String with HTML content in Razor MVC

I have a string coming from Database as :

<strong>Hello</strong>

Now i want my razor view to display is as:

Hello

How to do this Decoding in Razor?

like image 523
Prashant Avatar asked Dec 04 '22 04:12

Prashant


1 Answers

Use HtmlHelper.Raw. That will prevent decoding your string from the database by the view engine:

@Html.Raw(someString)

If the string is encoded in your database, then you need to call WebUtility.HtmlDecode:

@Html.Raw(WebUtility.HtmlDecode(someString))
like image 124
Patrick Hofman Avatar answered Dec 21 '22 07:12

Patrick Hofman