RadzenTemplateForm invokes Submit callback with null when using EditContext instead of Data #803

Open
opened 2026-01-29 17:44:39 +00:00 by claunia · 0 comments
Owner

Originally created by @Flachdachs on GitHub (Apr 9, 2023).

You can use a RadzenTemplateForm with Data="someDataObject" and everything works fine. Instead of Data you can also use an EditContext where Model is set to someDataObject. EditContext provides some useful events when you want to react on e.g. field changes. You only need to assign a single event handler instead of doing this for every form field. This works well so far, except ...

Describe the bug

... when you submit the form the Submit callback is called with null instead of the changed model.

To Reproduce

<RadzenTemplateForm TItem="Data" EditContext="editContext" Submit="saveData">
    <RadzenTextBox Name="@nameof(Data.Field)" @bind-Value="@model.Field"/>
    <RadzenButton Text="Save"/>
</RadzenTemplateForm>
@code {
    private Data model;
    private EditContext editContext;

    protected override void OnInitialized() {
        model = new Data("foo");
        editContext = new EditContext(model);
    }

    private void saveData(Data formData) {
        // formData is null, but both model and editContext.Model have the actual form data
    }

    record Data(string Field);
}

Expected behavior
When the parameter Data is not set but EditContext is given then set Data to (TItem)EditContext,Model in OnParametersSet.
Or, in OnSubmit call await Submit.InvokeAsync((TItem)EditContext.Model).

Originally created by @Flachdachs on GitHub (Apr 9, 2023). You can use a `RadzenTemplateForm` with `Data="someDataObject"` and everything works fine. Instead of Data you can also use an `EditContext` where `Model` is set to `someDataObject`. `EditContext` provides some useful events when you want to react on e.g. field changes. You only need to assign a single event handler instead of doing this for every form field. This works well so far, except ... **Describe the bug** ... when you submit the form the `Submit` callback is called with `null` instead of the changed model. **To Reproduce** ```razor <RadzenTemplateForm TItem="Data" EditContext="editContext" Submit="saveData"> <RadzenTextBox Name="@nameof(Data.Field)" @bind-Value="@model.Field"/> <RadzenButton Text="Save"/> </RadzenTemplateForm> @code { private Data model; private EditContext editContext; protected override void OnInitialized() { model = new Data("foo"); editContext = new EditContext(model); } private void saveData(Data formData) { // formData is null, but both model and editContext.Model have the actual form data } record Data(string Field); } ``` **Expected behavior** When the parameter Data is not set but EditContext is given then set Data to `(TItem)EditContext,Model` in OnParametersSet. Or, in OnSubmit call `await Submit.InvokeAsync((TItem)EditContext.Model)`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#803