0

I have the following string in my table column

<p>img page&nbsp;<img alt="" src="/fileman/Uploads/Images/Capture.PNG" style="height:255px; width:365px" /></p>

which I display like so in the view:

<dt>
            @Html.DisplayNameFor(model => model.Body)
        </dt>

However I get the actual string as the output, <p> tags do not actually become <p> tags and the img is not rendered.

How to make it render as html?

frc
  • 548
  • 2
  • 10
  • 20
  • 2
    use `@Html.Raw()` – Liam Nov 02 '16 at 16:36
  • 1
    Thanks! @Html.Raw(Model.Body) – frc Nov 02 '16 at 16:44
  • For future seekers, this question has a specific answer that the previous question does not: do not use a lambda for you model. For example: `@Html.Raw(DisplayFor(m=>m.column))` will fail. You literally want `@Html.Raw(Model.column)`. – user4593252 Oct 17 '17 at 00:10

2 Answers2

2

This should work as intended

@Html.Raw(Model.Body)
Liam
  • 27,717
  • 28
  • 128
  • 190
Daniel Mackenzie
  • 204
  • 3
  • 14
0

Assuming @model.Body has the html with the <p> tags in, using @Html.Raw(model.Body) should give you your desired result.

Captain Squirrel
  • 237
  • 5
  • 15