Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc - display rich text code in View

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

like image 243
dtjmsy Avatar asked Dec 06 '25 13:12

dtjmsy


1 Answers

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.

like image 119
Wouter de Kort Avatar answered Dec 10 '25 11:12

Wouter de Kort



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!