2013-11-15 81 views
1

我有這樣的事情:如何從控制器內的html內容中獲取文本?

using (var context = new MyDb()) 
{ 
    var post = context.Posts.Where(p => p.ThreadId == item).OrderBy(p => p.DateCreated).First(); 
    ViewBag.Description = post.Conent; //post.Content contains content of the post; that means html + user text 
} 

目前我ViewBag.Description包含一切,是的post.Content裏面,我需要它僅包含文本。我該怎麼做?

+0

可能重複[我怎樣才能從ASP.NET?](http://stackoverflow.com/questions一個字符串中去除HTML標籤/ 785715/how-can-i-strip-html-tags-from-a-string-in-asp-net) – Andrei

+0

使用Regex刪除html標籤 –

回答

2

使用此功能從一個字符串中刪除HTML標籤:

public string StripHtml(string text) 
{ 
    return Regex.Replace(text, "<(.|\\n)*?>", string.Empty); 
} 
相關問題