3

How would you do to display rendered html code like this <b>short article</b> and display it as bold short articl in an ASP.net mvc 3 view ?

I tried out @System.Web.HttpUtility.HtmlDecode(item.short_article); but doesn' t work

thanks

1 Answer 1

8

You can use HtmlHelper.Raw. It will return markup that is not HTML encoded.

You need to be aware however of the security risks when outputting HTML like this. If a user enters some HTML code that contains Javascript and save it to the database, your page will render and execute this script.

If there is a risk of users entering malicious data for your short_article field you should strip their input based on a whitelist of tags you want to allow.

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

2 Comments

It works perfect ! Millions thanks :), the html code is just for retrieving from my database, no update from user, no risk of javascript attack, though thanks for your remark. Thanks again
Is your code Encoded before you try to use the HTML.Raw function? if it is then the Raw will output the encoded html, not the actual html.

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.