Sunday 15 June 2014

asp.net mvc - MVC3 EF Search DB fields but strip HTML -


I am using Entity Framework with MVC 3 and trying to search on a description field but the problem It is that the description field contains HTML in it like "& lt; div class =" section "/> Can I do a terrible search that only searches for content outside the HTML tag?

  References back. Categories Where (i = & gt; i.Name.Contains (searchText) & I.Description.Contains (searchText))   

Thanks advance!

let's go to the methods of extracting text from an HTML document.

You only need to do the following:

  var doc = new HtmlDocument (); Doc.LoadHtml (htmlStr); Var node = doc.DocumentNode; Var textContent = node. Intertext;   

or very less awesome method:

  public static string strip HTML (string HTML string) {string pattern = @ "& lt; (. | N) * & gt ;? "; Return Regex.Replace (html string, pattern, string.Empty); }   

all together

  return strip HTML (references categories where (i => i.Name. Compatible (search text) and Amp; i. Description.com (search text)))    

No comments:

Post a Comment