How does one resolve this Blazor error?
EditForm requires either a Model parameter, or an EditContext parameter
I have created a minimally reproducible example below. The issue seems to be because the model is not instantiated...Why does the following simple page throw this error?
@page "/"
<EditForm @Model="@person">
<input @bind="@person.FirstName" />
<input @bind="@person.LastName" />
</EditForm>
@code
{
public Person person = new Person();
protected override Task OnInitializedAsync()
{
person = new Person
{
FirstName = "Fred",
LastName = "Flintstone"
};
return base.OnInitializedAsync();
}
}
I can not only tell you the error, but tell you how to check it while typing in VS.
Change to this:
<EditForm Model="@person">
(i.e. with no "@" sign on Model)
When you're typing in the <Editform> line, when you press space, you'll see the list of expected variables, several of which start with @, like @ref, and several which do not, like Model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With