Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditForm requires either a Model parameter, or an EditContext parameter

Tags:

c#

blazor

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();
    }
}
like image 840
John S Avatar asked Aug 03 '26 10:08

John S


1 Answers

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.

like image 136
Bennyboy1973 Avatar answered Aug 07 '26 06:08

Bennyboy1973



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!