I'm using Blazor to create a form where users need to select a "roda" from a dropdown.
The problem is that both the custom error message i defined in the viewModel ("Por favor escolha uma roda") and the default error message appear when no selection is made. I only want my custom error message to be displayed.
How can I ensure that only the custom error message appears?
My ViewModel has a validation rule to show an error message if no "roda" is selected:
[Required(ErrorMessage = "Por favor escolha uma roda")] public int? rodaEscolhida { get; set; }In the form, I'm binding the property like this:
<div class="mb-3"><label for="roda" class="form-label">RODA:</label><InputSelect id="roda" @bind-Value="ProductViewModel.rodaEscolhida" class="form-control"><option hidden value="">Selecione...</option> @foreach (var component in Components.Where(c => c.tipo == "RODA")) {<option value="@component.Id">@component.nome</option> }</InputSelect><ValidationMessage For="() => ProductViewModel.rodaEscolhida" class="text-danger" /></div>