How do I call a method from a static context within a renderfragment Blazor

I have this renderfragment that I am assigning as a menu and I need to be able to clear the list from within this renderfragment and I can’t seem to get it to work. I have tried event callbacks, actions, delagates and everytime I run into this error: Keyword ‘this’ is not available in the current context. I also cannot pass any parameters through the builder it gives me this error: Cannot convert initializer type ‘lambda expression’ to target type ‘Microsoft.AspNetCore.Components.RenderFragment’. So how can I clear this list in this context? The problem is within the button: ClearListAction(). This also doesnt work: OnCLick=(() => webhookList.Clear()) I get the same error about ‘this’.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> public delegate void ClearWebhooksAction(); // Delegate for clearing
public static ClearWebhooksAction ClearListAction { get; set; } // Delegate reference
public RenderFragment menu =
@<Menu>
@if (webhookList.Count > 0)
{
<MudTabs Elevation="0" Rounded="true" ApplyEffectsToContainer="true" Centered="true" PanelClass="mud-tabs-overlay" MinimumTabWidth="100%">
<MudTabPanel Icon="@Icons.Material.Filled.Phishing" Text="Webhooks">
@foreach (var n in webhookList)
{
string routerLink = "/cryptos/" + n.Id;
ClearListAction = () => webhookList.Clear();
<MenuItem RouterLink=@routerLink Class="notifications">
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceEvenly">
<div style="flex:20%">
<Avatar size="40px" src="@n.Avatar"/>
</div>
<div style="flex:65%">@n.Subtitle</div>
<div style="flex:15%">
@if (n.IsActive)
{
<MudIcon Icon="@Icons.Material.Outlined.NotificationsActive" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/>
}
else
{
<MudIcon Icon="@Icons.Material.Outlined.AddAlert" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/>
}
</div>
</MudStack>
</MenuItem>
}
@if (webhookList.Count > 0)
{
<div class="dismiss">
**<MudButton Class="list-button" Variant="Variant.Outlined" Size="MudBlazor.Size.Small" Color="MudBlazor.Color.Primary" OnClick="@(() => ClearListAction())" Style="font-size:14px !important">Dismiss</MudButton>**
</div>
}
</MudTabPanel>
<MudTabPanel Icon="@Icons.Material.Filled.CurrencyBitcoin" Text="Positions">
@foreach (var n in positionList)
{
string routerLink = "/cryptos/" + n.Id;
<MenuItem RouterLink=@routerLink Class="notifications">
<MudStack Row="true" AlignItems="AlignItems.Center">
<td>
<Avatar size="30px" src="@n.Avatar"/>
</td>
<td>@n.Subtitle</td>
<td>
@if (n.IsActive)
{
<MudIcon Icon="@Icons.Material.Outlined.NotificationsActive" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/>
}
else
{
<MudIcon Icon="@Icons.Material.Outlined.AddAlert" Color="MudBlazor.Color.Info" Style="font-size:20px; text-align: right" Title="Favorite" Class="notifications"/>
}
</td>
</MudStack>
</MenuItem>
}
@* @if(positionList.Count > 0) *@
@* { *@
@* <div class="dismiss"> *@
@* <MudButton Variant="Variant.Outlined" Size="MudBlazor.Size.Small" Color="MudBlazor.Color.Primary">Dismiss</MudButton> *@
@* </div> *@
@* } *@
</MudTabPanel>
</MudTabs>
}
else
{
<MenuItem Style="padding: 1rem;">
No notificaions to display
</MenuItem>
}
</Menu>;
</code>
<code> public delegate void ClearWebhooksAction(); // Delegate for clearing public static ClearWebhooksAction ClearListAction { get; set; } // Delegate reference public RenderFragment menu = @<Menu> @if (webhookList.Count > 0) { <MudTabs Elevation="0" Rounded="true" ApplyEffectsToContainer="true" Centered="true" PanelClass="mud-tabs-overlay" MinimumTabWidth="100%"> <MudTabPanel Icon="@Icons.Material.Filled.Phishing" Text="Webhooks"> @foreach (var n in webhookList) { string routerLink = "/cryptos/" + n.Id; ClearListAction = () => webhookList.Clear(); <MenuItem RouterLink=@routerLink Class="notifications"> <MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceEvenly"> <div style="flex:20%"> <Avatar size="40px" src="@n.Avatar"/> </div> <div style="flex:65%">@n.Subtitle</div> <div style="flex:15%"> @if (n.IsActive) { <MudIcon Icon="@Icons.Material.Outlined.NotificationsActive" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/> } else { <MudIcon Icon="@Icons.Material.Outlined.AddAlert" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/> } </div> </MudStack> </MenuItem> } @if (webhookList.Count > 0) { <div class="dismiss"> **<MudButton Class="list-button" Variant="Variant.Outlined" Size="MudBlazor.Size.Small" Color="MudBlazor.Color.Primary" OnClick="@(() => ClearListAction())" Style="font-size:14px !important">Dismiss</MudButton>** </div> } </MudTabPanel> <MudTabPanel Icon="@Icons.Material.Filled.CurrencyBitcoin" Text="Positions"> @foreach (var n in positionList) { string routerLink = "/cryptos/" + n.Id; <MenuItem RouterLink=@routerLink Class="notifications"> <MudStack Row="true" AlignItems="AlignItems.Center"> <td> <Avatar size="30px" src="@n.Avatar"/> </td> <td>@n.Subtitle</td> <td> @if (n.IsActive) { <MudIcon Icon="@Icons.Material.Outlined.NotificationsActive" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/> } else { <MudIcon Icon="@Icons.Material.Outlined.AddAlert" Color="MudBlazor.Color.Info" Style="font-size:20px; text-align: right" Title="Favorite" Class="notifications"/> } </td> </MudStack> </MenuItem> } @* @if(positionList.Count > 0) *@ @* { *@ @* <div class="dismiss"> *@ @* <MudButton Variant="Variant.Outlined" Size="MudBlazor.Size.Small" Color="MudBlazor.Color.Primary">Dismiss</MudButton> *@ @* </div> *@ @* } *@ </MudTabPanel> </MudTabs> } else { <MenuItem Style="padding: 1rem;"> No notificaions to display </MenuItem> } </Menu>; </code>
    public delegate void ClearWebhooksAction(); // Delegate for clearing

    public static ClearWebhooksAction ClearListAction { get; set; } // Delegate reference


    public RenderFragment menu = 
        @<Menu>
            
            @if (webhookList.Count > 0)
            {
                <MudTabs Elevation="0" Rounded="true" ApplyEffectsToContainer="true" Centered="true" PanelClass="mud-tabs-overlay" MinimumTabWidth="100%">
                    <MudTabPanel Icon="@Icons.Material.Filled.Phishing" Text="Webhooks">
                        @foreach (var n in webhookList)
                        {
                            string routerLink = "/cryptos/" + n.Id;
                            ClearListAction = () => webhookList.Clear();
                            <MenuItem RouterLink=@routerLink Class="notifications">
                                <MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceEvenly">
                                    <div style="flex:20%">
                                        <Avatar size="40px" src="@n.Avatar"/>
                                    </div>
                                    <div style="flex:65%">@n.Subtitle</div>
                                    <div style="flex:15%">
                                        @if (n.IsActive)
                                        {
                                            <MudIcon Icon="@Icons.Material.Outlined.NotificationsActive" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/>
                                        }
                                        else
                                        {
                                            <MudIcon Icon="@Icons.Material.Outlined.AddAlert" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/>
                                        }
                                    </div>
                                </MudStack>
                            </MenuItem>
                        }

                        @if (webhookList.Count > 0)
                        {
                            <div class="dismiss">
                                **<MudButton Class="list-button" Variant="Variant.Outlined" Size="MudBlazor.Size.Small" Color="MudBlazor.Color.Primary" OnClick="@(() => ClearListAction())" Style="font-size:14px !important">Dismiss</MudButton>**
                            </div>
                        }
                    </MudTabPanel>
                    <MudTabPanel Icon="@Icons.Material.Filled.CurrencyBitcoin" Text="Positions">
                        @foreach (var n in positionList)
                        {
                            string routerLink = "/cryptos/" + n.Id;
                            <MenuItem RouterLink=@routerLink Class="notifications">
                                <MudStack Row="true" AlignItems="AlignItems.Center">
                                    <td>
                                        <Avatar size="30px" src="@n.Avatar"/>
                                    </td>
                                    <td>@n.Subtitle</td>
                                    <td>
                                        @if (n.IsActive)
                                        {
                                            <MudIcon Icon="@Icons.Material.Outlined.NotificationsActive" Color="MudBlazor.Color.Info" Style="font-size:20px;text-align: right" Title="Favorite" Class="notifications"/>
                                        }
                                        else
                                        {
                                            <MudIcon Icon="@Icons.Material.Outlined.AddAlert" Color="MudBlazor.Color.Info" Style="font-size:20px; text-align: right" Title="Favorite" Class="notifications"/>
                                        }
                                    </td>
                                </MudStack>
                            </MenuItem>
                        }
                        @* @if(positionList.Count > 0) *@
                        @* { *@
                        @* <div class="dismiss"> *@
                        @*     <MudButton Variant="Variant.Outlined" Size="MudBlazor.Size.Small" Color="MudBlazor.Color.Primary">Dismiss</MudButton> *@
                        @* </div> *@
                        @* } *@
                    </MudTabPanel>
                </MudTabs>
            }
            else
            {
                <MenuItem Style="padding: 1rem;">
                    No notificaions to display
                </MenuItem>
            }
        </Menu>;

it is passed like this in my blazor code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> <Dropdown Overlay=@menu Placement="AntDesign.Placement.Bottom" Class="notifications" Arrow>
<MudBadge Content="@(notificationCount)" Color="MudBlazor.Color.Primary" Overlap="true" Origin="Origin.CenterRight">
<Icon Type="bell" Theme="outline" OnClick="() => OpenDrawer(MudBlazor.Anchor.End)"/>
</MudBadge>
</Dropdown>
</code>
<code> <Dropdown Overlay=@menu Placement="AntDesign.Placement.Bottom" Class="notifications" Arrow> <MudBadge Content="@(notificationCount)" Color="MudBlazor.Color.Primary" Overlap="true" Origin="Origin.CenterRight"> <Icon Type="bell" Theme="outline" OnClick="() => OpenDrawer(MudBlazor.Anchor.End)"/> </MudBadge> </Dropdown> </code>
 <Dropdown Overlay=@menu Placement="AntDesign.Placement.Bottom" Class="notifications" Arrow>
                    <MudBadge Content="@(notificationCount)" Color="MudBlazor.Color.Primary" Overlap="true" Origin="Origin.CenterRight">
                        <Icon Type="bell" Theme="outline" OnClick="() => OpenDrawer(MudBlazor.Anchor.End)"/>
                    </MudBadge>
                </Dropdown>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật