Decode String with HTML content in Razor MVC

2019-04-12 11:43发布

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?

2条回答
我只想做你的唯一
2楼-- · 2019-04-12 11:46

You can use @Html.Raw("<strong> Hello </strong>")

查看更多
Anthone
3楼-- · 2019-04-12 12:03

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))
查看更多
登录 后发表回答