razorhtml-encode

Convert Html to plain text with razor


I have this rich text stored in the database

<p>   <em><strong>strong</strong> and <em>em tag</em> normal text <u>

It is stored as a string with its tags.

Now I want ti put this text in the title of <a> tag without displaying all the html code.

I've tried

<a name="modal" title="@HttpUtility.HtmlDecode(MyVariable).ToString()"> link </a>

But it still displays all the tags.


Solution

  • You can remove the tags using regex:

    string plainText = Regex.Replace(MyVariable, "<.*?>", string.Empty);