ASP.NET MVC SQL HTML Formatting

I have an SQL table that contains HTML formatting for the displayed text.

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

In 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 looks fine without HTML formatting. Can anyone help solve the problem I am having?

+4
source share
1 answer

You should use @ Html.Raw () for this purpose.

Instead

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

Using

@Html.Raw(item.Body)

Link .

+6
source

All Articles