How do you display form validation error messages adjacent to the form fields in Blazor? How do you display a validation message specific to a field in a Blazor form?
This code will help you to understand how to display form validation error messages adjacent to the form fields in Blazor and to display a validation message specific to a field in a Blazor form.
How do you display form validation error messages adjacent to the form fields in Blazor? How do you display a validation message specific to a field in a Blazor form? You have to use the <ValidationMessage> tag with the “For” attribute lambda expression pointing to the form field.
[Person.cs]
using System.ComponentModel.DataAnnotations;
public class Person
{
[Required]
[StringLength(15, ErrorMessage = "{0} length must be between {2} and {1}.", MinimumLength = 6)]
public string FirstName { get; set; }
[Required]
[DataType(DataType.Password)]
[StringLength(15, ErrorMessage = "{0} length must be between {2} and {1}.", MinimumLength = 6)]
public string LastName { get; set; }
[Required]
[Range(1, 100, ErrorMessage = "Age should a number between (1-100).")]
public int Age { get; set; }
}
How do you display form validation error messages adjacent to the form fields in Blazor? How do you display a validation message specific to a field in a Blazor form?
You have to use the <ValidationMessage> tag with the “For” attribute lambda expression pointing to the form field.
[Person.cs]
[FormValidation.Razor]
need an explanation for this answer? contact us directly to get an explanation for this answer