14

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.

1
  • Thanks but it did not work for me, but this one worked :) : @Html.Raw(HttpUtility.HtmlDecode(inputText)) Commented Dec 1, 2016 at 13:42

2 Answers 2

31

You should use:

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

Decode and then render in html

Sign up to request clarification or add additional context in comments.

2 Comments

I've edited this post, please learn how to do this on your own in future :)
What happens if the html contains custom html helpers like <strong>@ABC("test")</strong>? Which would work if placed directly in a cshtml file. But inside a string?
9

To render any string (which includes HTML tags) -received from the model- as HTML, use:

@Html.Raw(Model.SomeString)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.