在剃刀MVC 3删除HTML格式 [英] Remove HTML formatting in Razor MVC 3

查看:143
本文介绍了在剃刀MVC 3删除HTML格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC 3的Razor视图引擎。

I am using MVC 3 and Razor View engine.

我所试图做的

我正在使用MVC 3的博客,我想删除像&LT所有HTML格式标记; P> < B> < I>

I am making a blog using MVC 3, I want to remove all HTML formatting tags like <p> <b> <i> etc..

对于我使用下面的code。 (它的工作)

For which I am using the following code. (it does work)

 @{
 post.PostContent = post.PostContent.Replace("<p>", " ");   
 post.PostContent = post.PostContent.Replace("</p>", " ");
 post.PostContent = post.PostContent.Replace("<b>", " ");
 post.PostContent = post.PostContent.Replace("</b>", " ");
 post.PostContent = post.PostContent.Replace("<i>", " ");
 post.PostContent = post.PostContent.Replace("</i>", " ");
 }

我觉得有绝对有成为一个更好的方式来做到这一点。任何人都可以请指导我在此。

I feel that there definitely has to be a better way to do this. Can anyone please guide me on this.

推荐答案

亚罗舍维奇,

下面是我现在用的..

Here is what I use now..

post.PostContent = Regex.Replace(post.PostContent, @"<[^>]*>", String.Empty);

这篇关于在剃刀MVC 3删除HTML格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆