如何在视图 MVC 中删除元标记的 html 标记?

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

我有元标记,它包含 html 标记。我想删除它。 示例内容为:

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

这是视图 MVC 中的代码片段

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

参数 @Model.description 包含内容文本。

您可以使用 regex 来替换您的 html 标签。例如,

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

否则您可以对 .Net 4.0+ 和旧版本使用 WebUtility.HtmlDecode HttpUtility.HtmlDecode.

希望对您有所帮助:)