cbug
July 16, 2023, 10:33am
1
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>
);
enchev
July 16, 2023, 11:27am
2
There is a busy dialog demo showing how to construct the content with code:
cbug
July 17, 2023, 12:02pm
3
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 });
enchev
July 17, 2023, 12:30pm
4
You are missing @using Radzen.Blazor
cbug
July 17, 2023, 12:32pm
5
Other places i am already using Radzen and following is how my imports looks..
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();
cbug
July 18, 2023, 6:21am
7
Thank you so much...
i am able to get the following button using following code
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?
enchev
July 18, 2023, 6:27am
8
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.