DialogService from inherited "codebehind" doesn't work for me

Just getting started here.

I'm having a hard time figuring out what the syntax should be to open a dialog and place an error message in it from my C# code.

For example, if a SQL error occurs, how do I pop up a dialog with the error in it?

BTW... At the moment I am getting a " We're sorry, but something went wrong at GitHub, so I don't have detailed example code for you. But basically, I was just trying to move the code as is to "code-behind".

If I try to implement the "ShowSimpleDialig" in "code-behind" it does't like the syntax no matter how I arrange it. It looks to me like it wants a dictionary and not the lamda that is being used in the example.

I finally got to the point were I can get a dialog to appear with:

async Task ShowSimpleDialog() => await dialogService.OpenAsync("Simple Dialog", messages);

However, I don't seem to be able to read the messages I pass to it and include it as part of the dialog.

Here's the example code I was referring to. How would I get this to work in "code-behind"?

async Task ShowSimpleDialog() => await dialogService.OpenAsync("Simple Dialog", ds =>

    @<RadzenCard Style="padding: 20px;">
    <p Style="margin-bottom: 10px;">Confirm?</p>
    <div class="row">
        <div class="col-md-12">
            <RadzenButton Text="Ok" Click="()=> ds.Close(true)" Style="margin-bottom: 10px; width: 150px" />
            <RadzenButton Text="Cancel" Click="()=> ds.Close(false)" ButtonStyle="ButtonStyle.Secondary"  Style="margin-bottom: 10px; width: 150px"/>
        </div>
    </div>
</RadzenCard>);

The simple dialog in our demo is opened exactly from code:

async Task ShowSimpleDialog() => await dialogService.OpenAsync("Simple Dialog", ds =>
        @<RadzenCard Style="padding: 20px;">
        <p Style="margin-bottom: 10px;">Confirm?</p>
        <div class="row">
            <div class="col-md-12">
                <RadzenButton Text="Ok" Click="()=> ds.Close(true)" Style="margin-bottom: 10px; width: 150px" />
                <RadzenButton Text="Cancel" Click="()=> ds.Close(false)" ButtonStyle="ButtonStyle.Secondary"  Style="margin-bottom: 10px; width: 150px"/>
            </div>
        </div>
    </RadzenCard>);

Make sure you have dialogService injected in your class and you are using latest Radzen.Blazor.

Thanks for the quick reply.

When I move the example into C#, I get

|Error|CS0411|The type arguments for method 'DialogService.OpenAsync(string, Dictionary<string, object>, DialogOptions)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

If I add the type with .OpenAsync<RadzenCard> (guessing that RadzenCard is correct). I get

Error CS1660 Cannot convert lambda expression to type 'Dictionary<string, object>' because it is not a delegate type HxDm.Server

What is your Radzen.Blazor version? Do you have Radzen and Radzen.Blazor namespace in your usings. Do you have DialogService injected in your class?

2.1.16

I believe the namespace and injection to be correct.

Latest Radzen.Blazor is 2.2.1

I updated all of my nuget packages. Now I get

Cannot implicitly convert type 'string' to 'Microsoft.AspNetCore.Components.RenderFragment'|HxDm.Server|

Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type

We suggest you check the Radzen sample application which shows how to use the DialogService. We can't tell why you are getting this compilation error.

The code I am receiving an error on is a direct copy to an inherited C# class. I will work with it further. Please let me know if you have any examples with it working in a C# class.

If you want to use the DialogService you need to use the first example with another page

dialogService.Open<DialogCardPage>($"Order {orderID}",
     new Dictionary<string, object>() { { "OrderID", orderID } },
     new DialogOptions(){ Width = "700px", Height = "530px" }));

Here DialogCardPage is another Blazor page which is displayed in the dialog.

I got that to work. Thank you.

Can you share your solution. I am also getting the same issue

1 Like