简体   繁体   中英

Render Html code with razor

I've searched over this website and I've looked over similar questions and i did not find the answer, I am sure it is somewhere but i did not find it, I have a string like this one for example :

string inputText = "<strong>Hello World</strong>"

This string comes from a certain request in control, and i have no power to change the model or the control. I can only change my razor view, using Html.Raw displays this result :

<strong>Hello World</strong>

And the result i want to be displayed is this one :

Hello World

How is it possible ?

PS: this is only a simple example, it can be any HTML Code.

You should use:

@Html.Raw(HttpUtility.HtmlDecode(inputText))

Decode and then render in html

要将任何字符串(包括HTML标记)从模型中接收为HTML,请使用:

@Html.Raw(Model.SomeString)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM