mvc3从文本框中剥离html属性

时间:2014-04-16 17:01:56

标签: html asp.net-mvc-3

我有一个论坛,它有一个富文本编辑器,允许发布一些Html。我有一个第二个文本框,我想用它来复制富文本编辑器中的任何内容,但这次剥离所有的html属性,例如:

[HttpPost]
public ActionResult posting(string post,thread newthread)
{
     //The post string has the Html in it from the text editor
     newthread.post = post;
     newthread.Nohtml= post;
     //The problem is above how can I strip out all HTML elements and save it in Nohtml
     db.threads.Add(newthread);
     db.SaveChanges();
}

正如您从上面的代码中看到的那样,帖子有HTML,但我想在将HTML保存到 Nohtml 时删除HTML,这样我就可以显示线程问题,我能以什么方式完成这个?

1 个答案:

答案 0 :(得分:0)

对于任何可能遇到此问题的人,我找到了解决方案

 newthread.Nohtml = Regex.Replace(post, @"<[^>]*>", String.Empty);
相关问题