Reputation: 8783
I've used ASP.NET MVC5 in my project.
I want to show data that recorded in database as a part of HTML page.
As a simplest data in database that recorded, I have <div>This is a div.</div>
And in cshtml file I have
<div>
@Html.DisplayFor(m => m.Description)
</div>
But data does not show as a HTML tag.
How can I explain to the browser that my data must be interpreted as an HTML tag?
Upvotes: 0
Views: 93
Reputation: 18165
Use @Html.Raw
instead of @Html.DisplayFor
.
Most of the HTML helper functions in Razor automatically encode the values to help prevent cross-site scripting attacks. If you're going to render raw HTML into the user's browser I hope you've sanitized it to prevent attacks.
Upvotes: 2