4

I have a SQL table that contains HTML formatting for text shown.

<strong>What Is EDI ?</strong><p>EDI is a method for communicating electronically with trading partners based upon standards.</p>

Within my MVC application there is an index.cshtml page below:

<h2>Index</h2>
<table>
    <tr>
        <th> @Html.DisplayNameFor(model => model.Body)</th>
        <th></th>
    </tr>
@foreach (var item in Model) {
    <tr>
        <td>@Html.DisplayFor(modelItem => item.Body)</td>
    </tr>
}
</table>

The problem is that the text is appearing as normal with no HTML formatting. Can anybody help to fix the issue I am having?

Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69
TerrorTot38
  • 191
  • 2
  • 14

1 Answers1

6

You have to use @Html.Raw() for this purpose.

Instead of

@Html.DisplayFor(modelItem => item.Body)

Use

@Html.Raw(item.Body)

Reference.

Community
  • 1
  • 1
Kartikeya Khosla
  • 18,743
  • 8
  • 43
  • 69