-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Blazor - Form Validation Exception when Refreshing #35000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
area-blazor
Includes: Blazor, Razor Components
feature-blazor-form-validation
This issue is related to forms validation in Blazor
Comments
To also note- I performed another test, using a nearly identical example provided with the .net 6.0 form validation example. @page "/admin/test"
@using System.ComponentModel.DataAnnotations
<EditForm Model="@starship" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<p>
<label>
Identifier:
<InputText @bind-Value="starship.Identifier" />
</label>
</p>
<p>
<label>
Description (optional):
<InputTextArea @bind-Value="starship.Description" />
</label>
</p>
<p>
<label>
Primary Classification:
<InputSelect @bind-Value="starship.Classification">
<option value="">Select classification ...</option>
<option value="Exploration">Exploration</option>
<option value="Diplomacy">Diplomacy</option>
<option value="Defense">Defense</option>
</InputSelect>
</label>
</p>
<p>
<label>
Maximum Accommodation:
<InputNumber @bind-Value="starship.MaximumAccommodation" />
</label>
</p>
<p>
<label>
Engineering Approval:
<InputCheckbox @bind-Value="starship.IsValidatedDesign" />
</label>
</p>
<p>
<label>
Production Date:
<InputDate @bind-Value="starship.ProductionDate" />
</label>
</p>
<button type="submit">Submit</button>
<p>
<a href="http://www.startrek.com/">Star Trek</a>,
©1966-2019 CBS Studios, Inc. and
<a href="https://www.paramount.com">Paramount Pictures</a>
</p>
</EditForm>
@code {
public class Starship
{
[Required]
[StringLength(16, ErrorMessage = "Identifier too long (16 character limit).")]
public string Identifier { get; set; }
public string Description { get; set; }
[Required]
public string Classification { get; set; }
[Range(1, 100000, ErrorMessage = "Accommodation invalid (1-100000).")]
public int MaximumAccommodation { get; set; }
[Required]
[Range(typeof(bool), "true", "true",
ErrorMessage = "This form disallows unapproved ships.")]
public bool IsValidatedDesign { get; set; }
[Required]
public DateTime ProductionDate { get; set; }
}
private Starship starship = new() { ProductionDate = DateTime.UtcNow };
private void HandleValidSubmit()
{
Console.WriteLine("HandleValidSubmit()");
}
protected override void OnInitialized()
{
Console.WriteLine("OnInitialized()");
base.OnInitialized();
}
protected override Task OnInitializedAsync()
{
Console.WriteLine("OnInitializedAsync()");
return base.OnInitializedAsync();
}
protected override void OnParametersSet()
{
Console.WriteLine("OnParametersSet()");
base.OnParametersSet();
}
protected override Task OnParametersSetAsync()
{
Console.WriteLine($"OnParametersSetAsync()");
return base.OnParametersSetAsync();
}
protected override void OnAfterRender(bool firstRender)
{
Console.WriteLine($"OnAfterRender(firstRender: {firstRender})");
base.OnAfterRender(firstRender);
}
protected override Task OnAfterRenderAsync(bool firstRender)
{
Console.WriteLine($"OnAfterRenderAsync(firstRender: {firstRender})");
return base.OnAfterRenderAsync(firstRender);
}
} The exact same exception occurs. Validation DOES work, but, when refreshing screen, unwanted stack trace is dumped into the console.
|
Thanks for the issue report. This is a dupe of #32411. We'll use the other issue to track fixing this. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area-blazor
Includes: Blazor, Razor Components
feature-blazor-form-validation
This issue is related to forms validation in Blazor
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
Exception thrown when using DataAnnocationsValidator AND ValidationsSummary.
To Reproduce
After selectively adding and removing code for a few hours to track down a very unhelpful exception- I have identified a potential bug with form validations.
Code To Reproduce
Produces this output when refreshing the page.
Removal of EITHER DataAnnotationsValidator OR ValidationSummary will make the exception go away.
Based on the documentation: https://docs.microsoft.com/en-us/aspnet/core/blazor/forms-validation?view=aspnetcore-6.0
This shouldn't cause issues.
##Remarks
This is the minimal amount of code I could leverage to reproduce this issue. The actual code base has proper data annotations for validations, yet, exhibits the same behaviour.
I am leveraging 6.0.100-preview.6.21355.2, with Visual Studio 2022 17.0.0 Preview 2.1.
The text was updated successfully, but these errors were encountered: