Klyroo.Form.DataAnnotations
0.1.0-preview.2
dotnet add package Klyroo.Form.DataAnnotations --version 0.1.0-preview.2
NuGet\Install-Package Klyroo.Form.DataAnnotations -Version 0.1.0-preview.2
<PackageReference Include="Klyroo.Form.DataAnnotations" Version="0.1.0-preview.2" />
<PackageVersion Include="Klyroo.Form.DataAnnotations" Version="0.1.0-preview.2" />
<PackageReference Include="Klyroo.Form.DataAnnotations" />
paket add Klyroo.Form.DataAnnotations --version 0.1.0-preview.2
#r "nuget: Klyroo.Form.DataAnnotations, 0.1.0-preview.2"
#:package Klyroo.Form.DataAnnotations@0.1.0-preview.2
#addin nuget:?package=Klyroo.Form.DataAnnotations&version=0.1.0-preview.2&prerelease
#tool nuget:?package=Klyroo.Form.DataAnnotations&version=0.1.0-preview.2&prerelease
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,MinandMax), with its localized messages. A[StringLength]with aMinimumLengthalso gets a validator rule for the minimum, and[Range]withtypeof(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. AnErrorMessageyou 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 theErrorMessageor 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 andIValidatableObjectrun 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 | Versions 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. |
-
net10.0
- Klyroo.Form.Core (= 0.1.0-preview.2)
-
net11.0
- Klyroo.Form.Core (= 0.1.0-preview.2)
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 |