Łukasz Baran
Łukasz Baran

Reputation: 1239

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

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

Upvotes: 3

Views: 2324

Answers (2)

David Anderson
David Anderson

Reputation: 68

Take a look at using Html.Raw() in your view.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038810

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.

Upvotes: 9

Related Questions