I am trying to call a radzen dialog razor page into a code-behind but getting a Null reference exception.
Kindly help
Most probably the DialogService is not injected or registered properly. Check our demos and documentation for reference.
I've the same problem!
DialogService ist registered and injected in the same way as the NotificationService. The NotificationService works but the DialogService does not.
I'm using both Services in a RCL. Is this maybe the Problem?
Make sure RadzenDialog is part of your main layout - check our getting started page for reference.
Sure, RadzenDialog ist part of the MainLayout (stored in RCL).
I've checked your getting started page, so NotificationDialog works fine...
And you have the DialogService injected in the page you are trying to use it?
Sure!
Program.cs
builder.Services.AddServicesFromRCL();
In RCL => RCLServiceCollection.cs:
public static class RCLServiceCollection
{
public static void AddServicesFromRCL(this IServiceCollection serviceCollection)
{
// Third Party Services
// Radzen Services
serviceCollection.AddScoped<DialogService>();
serviceCollection.AddScoped<NotificationService>();
serviceCollection.AddScoped<ContextMenuService>();
// Project Services
[...]
}
}
In RCL => MainLayout.razor
<RadzenLayout>
[...]
</RadzenLayout>
@* Start Radzen Services*@
<RadzenDialog />
<RadzenNotification />
<RadzenContextMenu />
@code {
bool sidebar1Expanded = true;
}
In RCL => DataGrid.razor:
@inject DialogService DialogService
<RadzenButton ButtonStyle="ButtonStyle.Success"
Icon="add_circle_outline"
class="mt-4 mb-4"
Text="Neu"
Click="@AddGegner" />
[...]
@code {
[...]
public async Task AddGegner()
{
await DialogService.OpenAsync<Kontakte.KontaktAdd>("Neuer Kontakt", options: new DialogOptions() { Width = "700px", Height = "512px", Resizable = true, Draggable = true });
}
}
NuGet packages Radzen and Radzen.Blazor are installed (in Server-App and in RCL) and updated to the latest version. NotificationService works, but DialogService not...
I think there would have been an exception if DialogService weren't injected - Blazor throws exception if it can't provide a value for a property which is injected. Something else is probably null. The debugger would reveal more.