'Blazor Repeatable EventCallback for Menu Item
I am working on a repeatable "Card" component that has a list of menu items and actions that this menu can take. However I cannot get the functionality to work. I am coming from React where something like this is quite common but cannot convert my thinking to Blazor. Help is appreciated.
Parent Component:
<Card Title="TestTitle" MenuActions=@MenuActions />
@code{
public Dictionary<string, EventCallback> MenuActions =
new Dictionary<string, EventCallback>(){
{"Test Case", HandleTestCase},
}
public void HandleTestCase(){
Console.WriteLine("Test Case");
}
}
Child Component:
<div>
<h2>@Title</h2>
<ul>
@foreach(var(menuTitle, menuAction) in MenuActions) {
<li>
<button onclick=@(menuAction.Invoke())>
@menuTitle
</button>
</li>
}
</div>
@code{
[Parameter]
public string Title {get; set;}
[Parameter]
public Dictionary<string, EventCallback> MenuActions {get; set;}
}
Totally lost, right now just getting this error:
error CS1503: Argument 2: cannot convert from 'method group' to 'EventCallback'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
