Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

The assembly does not contain a public invokable method with [JSInvokableAttribute]

$
0
0

We use Blazor WebAssembly and I want to call an non-static method in my Index.razor-File by JavaScript.

JavaScript:

(function () {    // keydown event    window.addEventListener("keydown", function (e) {        DotNet.invokeMethodAsync('MyBlazorWebAssemblyApp.Client', 'MyMethod');    });})();

Index.razor:

@page "/"@inject HttpClient Http@code {    // [...]    [JSInvokable]    public async Task MyMethod()    {        var lResponse = await Http.GetFromJsonAsync<object>("Controller/Action");    }}

When I execute the code by an keydown, then the developer tools in Microsoft Edge shows me the following error:

blazor.webassembly.js:1 System.ArgumentException: The assembly'MyBlazorWebAssemblyApp.Client' does not contain a public invokablemethod with [JSInvokableAttribute("MyMethod")].

When I replace the attribute [JSInvokable] by [JSInvokableAttribute("MyMethod")] then the same error appears.

How can I fix this problem?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>