@page "/"
@using System.ComponentModel.DataAnnotations
<h1>Hello, world!</h1>
<EditForm Model="@exampleModel" OnValidSubmit="HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<MatTextField id="name" @bind-Value="exampleModel.Name" />
<MatButton Type="submit">Submit</MatButton>
</EditForm>
@code
{
private ExampleModel exampleModel = new ExampleModel();
private void HandleValidSubmit()
{
Console.WriteLine("OnValidSubmit");
}
public class ExampleModel
{
[Required]
[StringLength(10, ErrorMessage = "Name is too long.")]
public string Name { get; set; }
}
}