user3493623
user3493623

Reputation: 91

How can I convert a string containing html to html itself?

I have a following string variable:

string example = "<div class=\"content\">" + Environment.NewLine + "[some content here]" + "/div";

How can I render it as html markup in the page body?

Upvotes: 0

Views: 222

Answers (1)

cederlof
cederlof

Reputation: 7403

Use Html-raw:

<body>
    @Html.Raw(example)
</body>

(However I would do it with caution. It is always best not to make HTML with strings if possible, as it poses a security risk and causes maintenance issues.)

Upvotes: 5

Related Questions