EditForm requires either a Model parameter, or an EditContext parameter
How does one resolve this Blazor Server 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
.