1,在控制器中实现去除html标签的静态方法
//去除html标签
public static string ReplaceHtmlMark(object Contents)
{
string HtmlString = Convert.ToString(Contents);
string[] RegexString = {
@"style=‘.*?‘",
@"class=‘.*?‘",
@"<param.*?>(</param>)?",
@"<embed.*?>(</embed>)?",
@"<object.*?>(</object>)?",
@"<strong.*?>(</strong>)?",
@"<span.*?>(</span>)?",
@"<p.*?>(</p>)?",
@"<u.*?>(</u>)?",
@"<em.*?>(</em>)?",
@"<div.*?>(</div>)?",
@"<o:p.*?>(</o:p>)?",
@"<font.*?>(</font>)?",
};
foreach (String str in RegexString)
{
Regex regex = new Regex(str, RegexOptions.IgnoreCase);
HtmlString = regex.Replace(HtmlString, string.Empty);
}
string[] RegexString2 = {
@"</font>",
@"</o:p>",
@"</div>",
@"</p>",
@"</object>",
@"</strong>",
@"</span>",
@"</ins>",
@" ",
};
foreach (String str2 in RegexString2)
{
Regex regex2 = new Regex(str2, RegexOptions.IgnoreCase);
HtmlString = regex2.Replace(HtmlString, string.Empty);
}
return HtmlString;
}
2,前台需要去除html标签的字段
@(HomeController.ReplaceHtmlMark(dr["Content"]))
asp.net 去除数据中带有的html标签