Search code examples
c#asp.net-mvcasp.net-mvc-4itexthtml-helper

Html.Raw in controller


I get content from editor so content include html tags like this "dddd"

I must remove html tags from content because I write this content to PDF(generate pdf in c#-controller action) using itextsharp.DLL but itextsharp content with html tags,it does not render html tags as you can see below screen

enter image description here

There is no Html.Raw function or HtmlHelper.Raw function in c#(action -controller)

What should I do?I try to remove html tags with regex but content is very complex and it is dynamic so there is many many html tags


Solution

  • One approach would be to use an HTML parser like the HTML Agility Toolpack. I've used this successfully for problems as you describe (but am otherwise unaffiliated with its development). From the site:

    This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).

    You'll find lots of examples online to tailor to your needs.