In Blazor 8 I have a component with an Edit Form.
Whenever I submit the Form, I always get the following error:
InvalidOperationException: EditForm requires either a Model parameter, or an EditContext parameter, please provide one of these.
This is how the component looks (uses SSR Server Mode):
<Sheet cssClass="mb-3">
<SheetTitle Text="Admin Area"></SheetTitle>
@if (Mini.Blocked)
{
<div>This Miniature has been blocked by an Admin</div>
}
else
{
<EditForm Model="@formData" FormName="BlockMiniature" method="post" OnSubmit="@OnBlockSubmit">
<input type="hidden" value="@Mini.Id" name="formData.MiniatureId"/>
<TextareaField Name="formData.Reason" @bind-Value="formData.Reason"></TextareaField>
<div class="flex justify-center">
<Button type="submit">Block Miniature</Button>
</div>
</EditForm>
}
</Sheet>
@code {
[Parameter]
public Miniature Mini { get; set; }
[SupplyParameterFromForm]
public BlockMiniatureForm formData { get; set; } = new();
public class BlockMiniatureForm
{
public Guid MiniatureId { get; set; }
public string Reason { get; set; }
}
public async Task OnBlockSubmit(EditContext arg)
{
BlockMiniatureForm form = (BlockMiniatureForm) arg.Model;
await mediatr.Send(new BlockMiniatureCommand(form.MiniatureId, form.Reason));
}
}
I tried to add the Parameters to the Form with @ and without. Makes no difference :(
I had the same problem in scafolded CRUD pages. I've fixed it by setting render mode as such: