Blazor has support for working with forms that are tied to models. There are a few components that know how to bind to properties of given types and display them accordingly as HTML DOM elements and a form component that takes care of binding to a model and validating it.
Form editing
For validating a model and allowing its edition, the component to use is EditForm. Its usage is shown in the following code snippet:
<EditForm
Model="@model"
OnSubmit="@OnSubmit"
OnInvalidSubmit="@OnInvalidSubmit"
OnValidSubmit="@OnValidSubmit">
...
<button>Submit</button>
</EditForm>
@code
{
var model = new Order(); //some model class
}
The EditForm component exposes two properties, as follows:
- Model (object): A POCO (short for Plain Old Common Language Runtime (CLR) Object) that contains the properties to bind to the form components; it is generally...