Klyroo.Form.DataAnnotations 0.1.0-preview.2

This is a prerelease version of Klyroo.Form.DataAnnotations.
dotnet add package Klyroo.Form.DataAnnotations --version 0.1.0-preview.2
                    
NuGet\Install-Package Klyroo.Form.DataAnnotations -Version 0.1.0-preview.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Klyroo.Form.DataAnnotations" Version="0.1.0-preview.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Klyroo.Form.DataAnnotations" Version="0.1.0-preview.2" />
                    
Directory.Packages.props
<PackageReference Include="Klyroo.Form.DataAnnotations" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Klyroo.Form.DataAnnotations --version 0.1.0-preview.2
                    
#r "nuget: Klyroo.Form.DataAnnotations, 0.1.0-preview.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Klyroo.Form.DataAnnotations@0.1.0-preview.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Klyroo.Form.DataAnnotations&version=0.1.0-preview.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Klyroo.Form.DataAnnotations&version=0.1.0-preview.2&prerelease
                    
Install as a Cake Tool

Klyroo.Form.DataAnnotations

Builds a typed Klyroo.Form schema from a C# model and its System.ComponentModel.DataAnnotations attributes, so a .NET developer can bind a form to a model the way they expect.

public sealed class Signup
{
    [Required, Display(Name = "Full name", Prompt = "Ada Lovelace")]
    [StringLength(80)]
    public string Name { get; set; } = "";

    [Required, EmailAddress]
    public string Email { get; set; } = "";

    [Range(18, 120)]
    public int Age { get; set; } = 18;

    [Required, DataType(DataType.Password), MinLength(8)]
    public string Password { get; set; } = "";

    [Compare(nameof(Password))]
    [DataType(DataType.Password)]
    public string ConfirmPassword { get; set; } = "";
}

var schema = FormSchema.For<Signup>(s => s.FromDataAnnotations());

var form = new FormController<Signup>(schema, new Signup());
await form.SubmitAsync(async (signup, ct) => await SaveAsync(signup, ct));   // signup is a Signup

// Blazor: <KlyFormEngine Schema="schema" Model="signup" OnSave="SaveAsync" />

What it maps:

  • [Required], [StringLength(max)] and [MaxLength] on a string, and [Range] with int or double inclusive bounds on a number, become the rules the engine already has (Required, MaxLength, Min and Max), with its localized messages. A [StringLength] with a MinimumLength also gets a validator rule for the minimum, and [Range] with typeof(decimal) or text bounds, an exclusive bound, or on a field that is not a number is a validator rule too, with the English message of the attribute. An ErrorMessage you set turns [StringLength], [MaxLength] and [Range] into validator rules with that message; on [Required] it replaces the engine message.
  • [Display] (name, description, prompt, order), [Editable(false)], [ReadOnly(true)] and [DataType] set the label, description, placeholder, position, disabled state and kind of control.
  • [MinLength], [RegularExpression], [EmailAddress], [Phone], [Url], [CreditCard] and [Compare] become validator rules that run while the user edits, with the message of the attribute (English, or the ErrorMessage or resource you give). The message of a validator rule is worked out when the rule fails, so it follows the UI culture of the validation, and the label, description, placeholder and [Required] message are fixed when the form is built.
  • Your own ValidationAttribute, attributes on the class and IValidatableObject run at submit on the model built from the form values. Their errors go to the field of the member they name, or to the form.

The schema is trim safe: nothing is compiled, and the model type is annotated so its public properties are kept. FromDataAnnotations() declares the other members of the model through AllMembers(), and UseDataAnnotations() reads the attributes of the fields you declared. The package needs Klyroo.Form.Core, so it works in a headless app too.

The full guide, with the limits, is in the Bind a C# model guide. The repository is at https://github.com/klyroo/klyroo-form.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-preview.2 34 11/29/2026
0.1.0-preview.1 36 11/29/2026