Skip to content

Forms typed fromyour C# model.

Declare a form from a C# model with FormSchema.For<TModel>: typed fields, rules, conditions and steps, on a controller with no UI dependency.

Install dotnet add package Klyroo.Form --prerelease
The Klyroo.Form line and its 4 stations
Klyroo.Form
  1. Typed fields
  2. Rules
  3. Steps
  4. Drafts
KlyrooStack Klyroo.Stack, the interchange of the network
Contact.razor 14 lines
Contact.razor
<KlyFormEngine TModel="Contact" Schema="_schema"
               Model="_contact" OnSave="SaveAsync" />

static readonly FormSchema<Contact> _schema =
  FormSchema.For<Contact>(s =>
  {
    s.Field(c => c.Name, f => f.Required());
    s.Field(c => c.Email, f => f.Required()
      .Rule(e => e.Contains('@'),
        "Enter a valid email address"));
    s.Field(c => c.Topic);
    s.Field(c => c.Message, f => f.Required()
      .AsTextarea().MaxLength(500));
  });

Each field is picked with an expression, so a renamed member does not compile, and an enum becomes a select.

The form sample data
Name *
Alice
Email *
alice
Enter a valid email address
Topic
Support
Message *
0 / 500
This field is required
Send
The model OnSave receives once the form is valid

Name and Topic keep their C# types: Topic is the enum, not a string nothing is written until every required field has a value the email is written only once the rule passes at most 500 characters OnSave gets this object, all or nothing

Contact {  Name    = "Alice",  Email   = "alice@example.com",  Topic   = Topic.Support,  Message = "Hello, I have a question."}

Beyond the first form

Show and require fields conditionally

VisibleWhen and Required take a condition typed against your model. A hidden field is not rendered, not validated and not written into the model.

Read the guide
C#
var type = s.Field(m => m.AccountType, f => f.AsRadio());
s.Field(m => m.Company, f => f
    .Required()
    .VisibleWhen(c => c.Get(type) == AccountType.Business));
var country = s.Field(m => m.Country, f => f.Default("FR"));
s.Field(m => m.VatNumber, f => f
    .VisibleWhen(c => c.Get(type) == AccountType.Business)
    .Required(c => c.Get(country) != "US")
    .DependsOn(country));
Account type: Business sample data
Personal Business
Company *
Initech
VAT number
FR 12 345

With Personal picked, Company and VAT number are not drawn.

Split a long form into steps

Steps can be skipped by a condition, and an async hook can stop the user from moving on. An error set there can block the step until it is cleared.

Read the guide
C#
s.Step("workspace", "Workspace", step =>
{
    slug = step.Field(m => m.Slug, f => f.Required().Label("Address"));
    plan = step.Field(m => m.Plan, f => f.AsRadio());
});
s.Step("billing", "Billing", step =>
{
    step.Field(m => m.VatNumber, f => f.Required());
}, skipWhen: c => c.Get(plan) == Tier.Free);
s.OnBeforeNext(async (form, stepIndex) =>
{
    if (stepIndex != 0) return true;
    var taken = await WorkspaceDirectory.IsTakenAsync(form.Get(slug)!);
    if (taken) form.SetError(slug, "This address is taken", blocking: true);
    return !taken;
});
Create your workspace sample data
  1. 1Workspace
  2. 2Billingskipped on Free
  3. 3Invite
Address *
acme
This address is taken
Free Team

Put a server error on a field

OnBeforeSubmit runs after the local rules pass. Return false after SetError and the message appears under the field, until the user edits it.

Read the guide
C#
var email = s.Field(m => m.Email, f => f.Required());
s.OnBeforeSubmit(async (registration, form) =>
{
    if (await accounts.IsEmailTakenAsync(registration.Email))
    {
        form.SetError(email, "This email is already registered");
        return false;
    }
    return true;
});
After Send sample data
Email *
ada@example.com
This email is already registered
Send

Everything it does

Typed schema
FormSchema.For<Order>(s => { s.Field(o => o.Seats, f => f.Range(1, 500)); ... }) declares fields from the members of a C# class and returns a handle per field, so a condition points at an earlier field through a captured local and controller.Get(seats) is an int. Kind-specific settings (AsTextarea, Range, Options, AsSwitch) are extension methods constrained on the type of the value, so a wrong kind does not compile. Group, List, MultiSelect, Step and Section declare nested objects, repeatable rows, multiple choice, wizards and pages.
Headless controller
FormController<TModel> manages values, touched state, errors, dirty tracking, steps and submission with no UI dependency, and Klyroo.Form.Core is NativeAOT compatible.
Typed components
KlyFormEngine<TModel> and KlyFormPage<TModel> render a FormSchema<TModel> (or a FormController<TModel>) with a Model, and infer TModel from the markup. OnSave receives the model, OnSubmit is raised with it, and a submit writes the values into the model you gave, all or nothing. KlyFormFieldView draws one field for a layout of your own, and KlyFieldTemplate draws the control of one field with a typed FormControlContext<TValue>.
Validation
Required and required-when checks, number bounds, password requirements, typed Rule and RuleAsync rules with a pending state (debounced, stale runs cancelled, awaited by submit), four validation modes and three triggers (blur, input, submit).
Model binding that cannot lose data
Values move between the form and the model with culture-independent conversions (a long, a decimal and a double keep every digit), a write into a model is all or nothing and rolls back when the save fails, and a value the user did not change keeps its ticks, kind and offset. Klyroo.Form.DataAnnotations reads [Required], [Range], [Display] and the other attributes into a typed schema, and runs IValidatableObject at submit.
Server errors
SetError attaches a message to a field, optionally blocking submission until the user edits it.
Conditional fields
VisibleWhen, Required(condition), DisabledWhen and skipWhen are plain delegates evaluated against the controller, and hidden fields, the children of hidden containers and the fields of skipped steps are left out of validation and of the model.
Dirty tracking
The controller compares values with an initial snapshot, resets a field or a section, and takes a new snapshot after a successful submit.
Wizards and pages
Multi-step forms with skippable steps and async before-next hooks, and sectioned pages that show a completion status per section.
Extensible
KlyFieldTemplate swaps the control of a typed field for your markup, AsCustom(key) plus CustomField<TValue>(key, renderer) registers one for the whole app, and FormFileValue fields are checked for Accept, MaxFileSize and multiple files in the core.
Localization
The built-in texts and validation messages follow the Klyroo.UI locale in twelve languages (English and French reviewed, the rest drafts), AddKlyrooForm(f => f.Texts("fr", t => t with { ... })) changes them, and FormMessages works without Blazor.
Unsaved changes
KlyFormNavigationGuard blocks navigation while the form is dirty, and ExportDraft() and RestoreDraft() keep a draft across a reload with the original baseline, so the restored draft is still dirty.
Overlays
FormService.CreateFormAsync<TModel> opens a form in a modal dialog, a side drawer or a fullscreen view hosted by KlyFormProvider (on KlyModal and KlySlideover: focus trap, Escape, focus restored) and returns the result as a task (FormSubmitOutcome<TModel> with the submitted model).
Agent ready
FormController<TModel> (like the runtime DynamicFormController) implements IFormRuntime, which lists the fields as IFormFieldAccess with JSON read and write (numbers keep their exact digits, a choice matches by value or label), so an agent bridge drives a form without knowing its model type.
Runtime mode
When the fields are only known at runtime, DynamicFormSchema and DynamicFieldSchema (namespace Klyroo.Form.Dynamic) describe the form as data, with values keyed by name, on the same engine. FormFieldKind has 33 values, and KlyDynamicFormEngine and KlyDynamicFormPage render each one. See Forms defined at runtime.

Packages

  • Headless engine: the typed FormSchema and FormController<TModel>, and for forms defined at runtime DynamicFormSchema, DynamicFormController and DynamicFormService. No UI dependency, trimmable, NativeAOT compatible.
  • Blazor components KlyFormEngine<TModel>, KlyFormPage<TModel>, KlyFormFieldView<TModel>, KlyFieldTemplate and KlyFormProvider, FormService, and the AddKlyrooForm() registration, plus KlyDynamicFormEngine, KlyDynamicFormPage and KlyDynamicFieldView for the runtime mode. Builds on Klyroo.UI and references Klyroo.Form.Core.
  • Builds a typed schema from a C# model and its DataAnnotations attributes, and runs IValidatableObject and your own validation attributes at submit. References Klyroo.Form.Core only, so it also works without Blazor.

Install it, then open the first page.

Change here for the other lines

  • Klyroo.UI Accessible Blazor components for the web and .NET MAUI Blazor Hybrid, styled with Tailwind CSS v4
  • Klyroo.Query Typed query model, URL state sync, and IQueryable / EF Core execution
  • Klyroo.Table Data lists with table and card-grid layouts, filters, selection and actions
  • Klyroo.Form Schema-driven forms, validation and wizards
  • Klyroo.Dashboard Dashboard controller, filters and Blazor blocks: stats, gauges, charts, tables and feeds
  • Klyroo.Display Code highlighting, secret and file list components, media player controls and file preview
  • Klyroo.Spreadsheet Import wizard for CSV, TSV and pasted data, with column and value mapping
  • Klyroo.Agent Bridge that lets AI agents read and act on Klyroo forms, dashboards and imports
  • Klyroo.Hotkey Server-side .NET client for Hotkey cloud browsers, human handoffs and signed webhooks
  • Klyroo.Stack Meta-package, MCP documentation server and dotnet new templates