Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP .NET MVC - How to send html from controller to view

Tags:

asp.net-mvc

I have text formated with HTML saved in database. Now what I want to do is to get that text and send it view, with all html formating. But all I get is: & lt; p & gt;

Which is no exactly what I want. Any ideas how to get

like image 948
Łukasz Baran Avatar asked Dec 09 '25 20:12

Łukasz Baran


1 Answers

Don't HTML encode in the view:

Razor:

@Html.Raw(Model.SomeHtmlStringComingFromTheDatabase)

WebForms:

<%= Model.SomeHtmlStringComingFromTheDatabase %>

Remark: by doing this you acknowledge that you fully understand the consequences of XSS attacks that your application becomes vulnerable to and that you do the necessary to sanitize this HTML if it comes from user input.

like image 103
Darin Dimitrov Avatar answered Dec 12 '25 10:12

Darin Dimitrov



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!