Getting Started

BlazorCodeFirst lets you write Blazor UI as plain C#. This page is itself rendered from Markdown, converted at build time and injected through Html.Raw.

Installation#

Add the runtime and the source generator to your project, then derive your components from BodyComponentBase.

A first component#

using Microsoft.AspNetCore.Components;
using BlazorCodeFirst;
using static BlazorCodeFirst.Html;

[Route("/")]
public partial class Home : BodyComponentBase
{
    protected override View Body =>
        Div[
            H1["Hello"],
            Span["Welcome to BlazorCodeFirst."]];
}

Values copied into generated code#

BlazorCodeFirst copies design-time value expressions into a generated file that has no using directives. Resolved type names are rewritten as global::-qualified names. If a type is still unresolved and its spelling depends on the source file's lexical context, the generator reports BCF3015 at that type name.

Fix the name, fully qualify it, move a source-generated type to a referenced project, or replace it with a hand-written C# type. A reference already rooted at global:: is preserved and left to normal C# resolution. Generic type arguments are checked independently.

Next steps#

An unhandled error has occurred. Reload 🗙