[英]remove HTML tags from cshtml webpage in asp.net mvc
I have following controller我有以下控制器
public ActionResult Dashboard()
{
return View(db.AB_Product_vs_Field.ToList());
}
I'm getting following view for above controller method which is containing with HTML tags(actually those field's values are saved in database with HTML tags)我得到了上面包含 HTML 标签的控制器方法的以下视图(实际上这些字段的值保存在带有 HTML 标签的数据库中)
How can I remove these html tags and show just the plain text.what's the least and simple effort for this我怎样才能删除这些 html 标签并只显示纯文本。为此所做的最简单的工作是什么
只需使用返回非 HTML 编码标记的 @Html.Raw() 即可。
这将删除 html 标签
@Regex.Replace(your_variable, @"<[^>]+>", "")
Regex
is the best option to do it.正则
Regex
是最好的选择。
Let us example:-让我们举例:-
If you want to remove any HTML tags:-如果您想删除任何 HTML 标签:-
String OnlyString = someString.replaceAll("<[^>]*>", "");
If you want to remove any specific HTML tag:-如果您想删除任何特定的 HTML 标签:-
String removedSpecific = someString.replaceAll("(?i)<td[^>]*>", "");
Hope above example will solve your issue.希望上面的例子能解决你的问题。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.