mvc3从文本框中剥离html属性
我有一个论坛,它有一个富文本编辑器,允许一些Html发布。我有第二个文本框,我想用它来复制富文本编辑器中的任何内容,但这一次去掉了所有html属性,例如:mvc3从文本框中剥离html属性,html,asp.net-mvc-3,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; newth
[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();
}
从上面的代码可以看出,post有HTML,但是我想在保存到Nohtml时去掉HTML,这样我就可以显示线程问题的预览,我可以用什么方式来实现这一点?对于任何可能有此问题的人,我已经找到了解决方案
newthread.Nohtml = Regex.Replace(post, @"<[^>]*>", String.Empty);
newthread.Nohtml=Regex.Replace(post,@“]*>”,String.Empty);
查找用于剥离HTML的库或编写一些代码来剥离HTML。有很多资源(以及其他问题)可以帮助您解决这个问题。尝试搜索。