Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor - How to display html content in a div tag?

Here is my razor code:

       <fieldset>
            <legend>Headline News</legend>

                @foreach (var item in Model)
                {
                    <div>@Html.DisplayFor(modelitem => item.Description)</div>
                }
        </fieldset>

The value for item.Description is HTML:

<table border="0" cellpadding="2" cellspacing="7" style="vertical-align:top;"><tr><td width="80" align="center" valign="top">
   {{ table info }}
</table>

I actually want to display the HTML content, but it shows up as HTML tags. Thanks in advance!

like image 533
WinFXGuy Avatar asked Jun 21 '12 19:06

WinFXGuy


1 Answers

You should use:

@foreach (var item in Model)
{
    <div>@Html.Raw(item.Description)</div>
}
like image 97
Mateusz Rogulski Avatar answered Oct 25 '22 23:10

Mateusz Rogulski