Search code examples
htmlasp.net-mvcmeta-tags

How to remove html tag of meta tag in view MVC?


I have meta tag and it contain html tag. I want to remove this. Example content as :

<p><b>This is red color</b><br>

This is snipped code in view MVC

<meta name="description" content="@Model.description" />

Parameter @Model.description contain content text.


Solution

  • You can use regex to replace your html tags. For example,

    string myContent = Regex.Replace(description, @"<(.|\n)*?>", string.Empty);
    

    Or-else you can use WebUtility.HtmlDecode for .Net 4.0+ and for older version HttpUtility.HtmlDecode.

    Hope it helps :)