Skip to content
Itay edited this page Aug 26, 2018 · 2 revisions

After using j2html with a Java project, I knew it was one of the best HTML builders I have used. After searching for something similar for a C# project, and not finding any, I decided to port the j2html to C# myself.

Getting started with DotNet2HTML

Import TagCreator to get started. DotNet2HTML's syntax is fluent and closely matched to HTML:

using static DotNet2HTML.TagCreator;

namespace Program
{
    class Program
    {
        public static void Main(string[] args)
        {
            Body(
                H1("Hello, World!"),
                Img().WithSrc("/img/hello.png")
            ).Render();
        }
    }
}

The C# code above becomes the HTML below:

<body>
    <h1>Hello, World!</h1>
    <img src="/img/hello.png">
</body>