Reputation: 10068
I have something like this:
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
}
Currently my ViewBag.Description
contains everything that is inside of post.Content
, and I need it to contain only text. How do I do it?
Upvotes: 1
Views: 474
Reputation: 44600
Use this function to remove HTML tags from a string:
public string StripHtml(string text)
{
return Regex.Replace(text, "<(.|\\n)*?>", string.Empty);
}
Upvotes: 2