1

I am storing some html inside an xml document similar to this:

<news>
    <item>
        <title>some title</title>
        <story>some text<![CDATA[<p/>]]> some more text</story>
    </item>
</news>

I read the xml into a model object that is used in an MVC 3 view with razor syntax. Everything displays fine except the html that I have in the CData sections is printed to the screen as is similar to this:

some title
some text<p/>some more text

My view looks like this:

<h2>@Model.Title</h2>
<p>
    @Model.Story
</p>

but obviously i'm missing something on the rendering of the story. I even tried doing a @HttpUtility.HtmlDecode(Model.Story) but that gave me the same result.

How can I get it to render this?

some title
some text

some more text

1 Answer 1

4

Use the Html.Raw helper:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.