0

I have a simple string variable that contains a portion of HTML inside. For example:

string contents = "<div><p>Hi how are you. <a href="#">Click here</a> if you want to know more";

I want to include this HTML in page:

<div class="description">
    @contents
</div>

However, it messes up the rest of the page because of unclosed tags.

Is there a function (or a helper) that reads and formats the HTML inside for example, to complete the HTML without errors:

@Html.DisplayProperHTML(contents)

This will render as:

<div><p>Hi how are you. <a href="#">Click here</a> if you want to know more</p></div>
1
  • As far as I know, there isn't any helper like this. You must write your own. Commented Oct 25, 2012 at 13:27

1 Answer 1

2

There is no such functionality built-in.

You can use the HTML Agility Pack to parse and fix broken HTML.

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.