Home > Enterprise >  How do i display html tags from sql serever database to html page?
How do i display html tags from sql serever database to html page?

Time:11-13

i want to display html tags which are in my database to a html webpage. Example:

this is the first post

(with the p tags) - this is stored in database with datatype of varchar(max). when i display this on webpage it displays it but not in html just in text. what am i doing wrong? When i inspect the element i see this <p>this is the first post</p>

CodePudding user response:

I believe you need to encapsulate your item with Html.Raw() as in for example:

@model IEnumerable<SOL.Models.Myhtmls>
@foreach (var item in Model)
{
    @Html.Raw(item.tag) //where tag is your model's property
}
  • Related