Skip to content

Using DataAnnotationsValidator with recreating model leads to renderer error (V2 only) #1732

@linkdotnet

Description

@linkdotnet

Given the following component:

<EditForm Model="model" OnValidSubmit="CreateTalk">
	<DataAnnotationsValidator />
	
	<InputText class="form-control" id="talk-title" @bind-Value="model.Title" />
	<button>Submit</button>
</EditForm>

@code {

	[Parameter]
	public EventCallback Created { get; set; }

	private Model model = new();
	
	private async Task CreateTalk()
	{
		await Created.InvokeAsync();
		model = new Model();
	}
	
	public sealed class Model
	{
		public string? Title { get; set; }
	}

}

And the following test:

var wasInvoked = false;
var cut = Render<TalkForm>(
	ps => ps.Add(p => p.Created, o => wasInvoked = true));
cut.Find("#talk-title").Change("title");

cut.Find("form").Submit();

wasInvoked.ShouldBeTrue();

we get an:

System.ArgumentException: The renderer does not have a component with ID 6.

The interesting part is when:

  • We don't new up the model after the emit (model = new Model();): the test passes
  • We remove the Validator (DataAnnotationsValidator): the test passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions