In Blazor, the [JSInvokable] attribute is used
to annotate a method, enabling it to be invoked from JavaScript code. The prerequisite for this functionality is that the method must be declared as
public.
Otherwise, a runtime error will be triggered when an attempt is made to call the method from JavaScript.
To fix the issue, ensure the methods annotated with the [JSInvokable] attribute are public.
@code {
[JSInvokable]
private static void MyStaticMethod() { } // Noncompliant
[JSInvokable]
internal void MyMethod() { } // Noncompliant
}
@code {
[JSInvokable]
public static void MyStaticMethod() { } // Compliant
[JSInvokable]
public void MyMethod() { } // Compliant
}