Hi, I am having problems to use SfDialogService component in a .net 6.0 and Blazor Server project.
I followed the link below to add the necessary code but keep getting System.NullReferenceException: 'Object reference not set to an instance of an object.' when it is called.
Please help, thanks
Peter
-----
Class SfDialogService - Blazor API Reference | Syncfusion
in program.cs, I added these lines
using Syncfusion.Blazor;
using Syncfusion.Blazor.Popups;
...
builder.Services.AddScoped<SfDialogService>();
builder.Services.AddSyncfusionBlazor(options => { options.IgnoreScriptIsolation = true; });
..
in razor file, I added these
@using Syncfusion.Blazor
@using Syncfusion.Blazor.Popups;
@inject SfDialogService DialogService
<button class="btn btn-primary" @onclick="Alert">Alert Modal</button>
@code {
private async Task Alert()
{
//await DialogService.AlertAsync(message);
await DialogService.PromptAsync("Prompt Dialog Content");
}
}
Hi Peter,
Greetings from Syncfusion support.
Please follow the below steps to render a predefined dialog using the register dialog service.
Step #1: Register the Syncfusion Blazor SfDialogService in the Program.cs file.
|
using Syncfusion.Blazor; using Syncfusion.Blazor.Popups;
builder.Services.AddScoped<SfDialogService>(); builder.Services.AddSyncfusionBlazor(); |
Step #2: Add the SfDialogProvider component in the MainLayout.razor file.
MainLayout.razor
|
<main> <article class="content px-4"> @Body <Syncfusion.Blazor.Popups.SfDialogProvider /> </article> </main> |
Step #3: Use the following code to render the predefined Dialog as an application.
|
@using Syncfusion.Blazor.Popups @inject SfDialogService DialogService <div> <button class="e-btn dlgbtn" @onclick="@AlertBtn">Alert</button> <button class="e-btn dlgbtn" @onclick="@ConfirmBtn">Confirm</button> <button class="e-btn dlgbtn" @onclick="@PromptBtn">Prompt</button> </div> @code { private async Task AlertBtn() { await DialogService.AlertAsync("10% of battery remaining", "Low Battery"); } private async Task ConfirmBtn() { bool isConfirm = await DialogService.ConfirmAsync("Are you sure you want to permanently delete these items?", "Delete Multiple Items"); } private async Task PromptBtn() { string promptText = await DialogService.PromptAsync(null, "Join Wi-Fi network", new DialogOptions() { ChildContent = @<table class="Table"> <tbody> <tr> <td>SSID:</td> </tr> </tbody> </table> }); } }
|
Please find the below sample for your reference.
Release Notes: https://blazor.syncfusion.com/documentation/release-notes/20.2.36?type=all#dialog
If you still have a problem, can you please share your Syncfusion package version and share the issue reproducible sample?
Regards,
Buvana S
This phenomenon is reproduced in package version 20.2.0.49.
The initial value of the title of ConfirmAsync, AlertAsync, and PromptAsync of SfDialogService is null, but NullReferenceException will occur if it is executed as null.
await DialogService.ConfirmAsync("content"); // NullReferenceException
await DialogService.ConfirmAsync("content", "title"); // No Problem
Hi Takuya,
We are glad to announce that our Essential Studio 2022 Volume 3 release v20.3.0.47 is rolled out and is available for download under the following link.
We have also included the fix for the issue "Throwing null reference exception when passing null values for dialog title in SfDialogService" with our Vol 3 Main release version 20.3.47. So please upgrade your package to the latest to resolve the issue from your end.
Release Notes: https://blazor.syncfusion.com/documentation/release-notes/20.3.47?type=all#dialog
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you require any further assistance.
Regards,