Luke101
Luke101

Reputation: 65278

How to create a doctype with TagBuilder

The ! in the doctype tag I cannot create. Is there a way to put the ! in a doctype tag using tagbuilder.

Upvotes: 1

Views: 162

Answers (1)

Panos
Panos

Reputation: 991

Since the Doctype is not an HTML tag, you can't use TagBuilder.

Although, you can return a normal MvcHtmlString.

public static class CustomHelpers
    {
        public static MvcHtmlString DocType(this HtmlHelper helper)
        {
            var docType = @"<!DOCTYPE ...>";
            return MvcHtmlString.Create(docType);
        }
    }

And then use it like that:

@Html.DocType()

Upvotes: 1

Related Questions