rohan koshti
rohan koshti

Reputation: 313

Pre tag to show html content from database

I am developing MVC application where I need to show some html content like image , hyperlink , bold , underline text , etc.

I save this content in SQL server database and fetch it from there.

But when I render it as @Model.Description it shows the text instead of html image or bold text.

But when I manually write such html content in pre tag, it is displayed well and good.

Please advise.

Upvotes: 2

Views: 664

Answers (1)

Nemanja Todorovic
Nemanja Todorovic

Reputation: 2820

When you just write razor syntax like @Model.SomeProperty it will automatically encode it. So html will be encoded this way and output will containt &gt etc... If you want to inject html you should use @Raw(Model.Property) but you need to be aware that this could inject some malicious js...

Upvotes: 3

Related Questions