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?

3
  • 2
    use @Html.Raw() Commented Nov 2, 2016 at 16:36
  • 1
    Thanks! @Html.Raw(Model.Body) Commented Nov 2, 2016 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). Commented Oct 17, 2017 at 0:10

2 Answers 2

2

This should work as intended

@Html.Raw(Model.Body)
Sign up to request clarification or add additional context in comments.

Comments

0

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

3 Comments

That gives me an error, "model does not exist in current contextt"
Does it give you the error when you remove the @ from model.body?
Model needs to be upercase @Html.Raw(Model.Body)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.