Reputation: 1590
I am using Code First and I am introducing test data into the data base everytime the model changes. The problem comes when I do the following:
context.News.Add(new News
{
Id = 3,
NewsTitle = "title",
NewsImage = "thumb.jpg",
NewsText = "text",
Venue = @"<iframe width=""1000"" height=""350"" frameborder=""0"" scrolling=""no"" marginheight=""0"" marginwidth=""0"" src=""https://maps.google.ro/maps?hl=ro&ie=UTF8&t=h&ll=46.778815,23.614479&spn=0.002572,0.010718&z=17&output=embed""></iframe>"
});
I have tried with \ instead of double quotes too...still nothing. The problem is that when I use the "Venue" on the page, it displays as plain text:
<div style="margin-top: 10px;">
@News.Venue
</div>
What should I do to get it as html?
Upvotes: 1
Views: 314
Reputation: 7140
There is a specific MvcHtmlString class that is designed to store strings that are HTML-encoded and should not be encoded again when rendering.
Upvotes: 0
Reputation: 15588
Use
@Html.Raw(News.Venue)
This will output News.Venue
in raw HTML, unencoded. See HtmlHelper.Raw on MSDN for more information. You may of course want to be careful of the content in .Venue
, if it comes from a third party, and sanitise it from scripts or unwanted content.
Upvotes: 1