Skip to content
This repository was archived by the owner on Dec 26, 2025. It is now read-only.
This repository was archived by the owner on Dec 26, 2025. It is now read-only.

Submitting form results in InvalidDataOperation "Could not find property named Person on object of type MyProject.BlazorServer.Pages.Person." #245

Description

@Bond-Addict

Example Code

Parent.razor

<ErrorBoundary Context="ErrorContext" @ref="errorBoundary">
    <ChildContent>
  <EditForm EditContext="EditContext" OnValidSubmit="ValidSubmit" FormName="PersonForm">
      <FluentValidationValidator />
      <InputText @bind-Value="Person.FirstName" />
      <ValidationMessage For="@(() => Person.FirstName)" />
      <br />
      <button style="background:green; padding:1em; color: white;" type="submit">Submit</button>
  </EditForm>
    </ChildContent>
    <ErrorContent>
        <div class="error"><span>An error occurred</span></div>
    </ErrorContent>
</ErrorBoundary>

@code{
    private EditContext EditContext { get; set; }
    public Person Person { get; set; }
    private FluentValidationValidator validator;

    protected override async Task OnInitializedAsync()
    {
         if (Person == null)
             Person = new Person();

        EditContext = new EditContext(Person);
        await base.OnInitializedAsync();
   }
}

Person.cs

namespace MyProject.BlazorServer.Pages
{
	public class Person
	{
		public string FirstName { get; set; } = string.Empty;
		public PersonAddress PersonAddress { get; set; } = new();
	}

	public class PersonValidator : AbstractValidator<Person>
	{
		public PersonValidator()
		{
			RuleFor(p => p.FirstName).Cascade(CascadeMode.Stop).NotEmpty().WithName("FirstName");
		}
	}
}

Image

Image

Image

Problem

ToFieldIdentifier is treating the class name as a property of its self. There is no Person.Person. I even tried to use .WithName() thinking that maybe it just needed to be manually set. This is sample code I'm using to debug a project I inherited which has totally jacked up validation. I assume that maybe there is some dependency that wasnt setup correct, but I can't find any reference to point to what would cause this exception and how to get past it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionQuestion about this projectTriageIssue needs to be triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions