Inside a Blazor component, I want to call a JS method from the HTML onclick event of an anchor tag, thus:
<a onclick="window.LoadImage();" class="@CssClass">@DisplayName</a>
My JS method is:
window.LoadImage = () => {
DotNet.invokeMethodAsync('MyProject', 'FireEvent').then();
}
Inside the JS method, I want to fire a C# static method to trigger an event, thus:
[JSInvokable]
public static void FireEvent()
{
StateEngine.LoadImage(DisplayName, Target);
}
[Parameter]
public string DisplayName { get; set; }
[Parameter]
public string Target { get; set; }
I can't get the JS method to find the C# method. I've tried multiple name configurations for the first parameter, like
MyProject (the assembly name)
MyProject.FolderName.ComponentName
FolderName.ComponentName
ComponentName
to name a few. I've also tried shuffling names through the second parameter.
How is this supposed to work? What am I missing?
P.S. Please disregard the bit about the instance properties in the static method. I've got a workaround for that, but don't want to clutter up the post.