How to show a dialog from the C# class and not from the razor file

Hello,

If i have dialogService injected in my C# class then how would i create a following code which is working in Razor and to make it work for C# class?

    var result = await DialogService.OpenAsync(title, ds =>
@<RadzenStack Gap="1.5rem">
    <p>@message</p>
    <RadzenStack Orientation="Orientation.Horizontal" Gap="0.5rem" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.SpaceBetween">
        <RadzenStack Orientation="Orientation.Horizontal">
            <RadzenButton Text="Ok" Click="() => ds.Close(true)" Style="width: 80px;" />
        </RadzenStack>
    </RadzenStack>
</RadzenStack>
);

There is a busy dialog demo showing how to construct the content with code:

Hello, i used the same example but it rendered as following..

    await DialogService.OpenAsync("", ds =>
    {
        RenderFragment content = b =>
        {
            b.OpenElement(0, "RadzenRating");
            b.AddAttribute(1, "Stars", 10);
            b.CloseElement();
        };
        return content;
    }, new DialogOptions() { ShowTitle = false, Style = "min-height:auto;min-width:auto;width:auto", CloseDialogOnEsc = false });

You are missing @using Radzen.Blazor

Other places i am already using Radzen and following is how my imports looks..

image

However i also tried on your site and it had same issue...

This should be

b.OpenComponent<RadzenRating>(0);
b.AddAttribute(1, "Stars", 10);
b.CloseComponent();

Thank you so much...

i am able to get the following button using following code

image

    await DialogService.OpenAsync("", ds =>
    {
        RenderFragment content = b =>
        {
            b.OpenComponent<RadzenButton>(1);
            b.AddAttribute(2, "Text", "Ok");
            //b.AddAttribute(3, "Click", "() => ds.Close(true)");
            b.AddAttribute(4, "Style", "width: 80px;");

            b.CloseComponent();
        };
        return content;
    }, new DialogOptions() { ShowTitle = false, Style = "min-height:auto;min-width:auto;width:auto", CloseDialogOnEsc = false });

But however if i uncomment the line.. b.AddAttribute(3, "Click", "() => ds.Close(true)");

then i get following error in the console.
Can you please suggest how would i call the close method on button click?

This is not how you should add event handlers in Blazor with code - I strongly suggest you to check official Microsoft documentation for reference. You can also assign an event handler of a button in razor and check the code generated in obj folder.