I have a Blazor application, and at some point I need to call my component’s code behind method.
In javascript:
DotNet.invokeMethodAsync('MyAssembly', 'MyAssembly.Components.Orders.Checkout.PlaceOrderAsync', paymentToken)
.then(result => {
// Handle success
console.log('C# method PlaceOrderAsync() called successfully.');
})
.catch(error => {
// Handle error
console.error('Error calling C# method PlaceOrderAsync():', error);
});
In Blazor component code-behind:
namespace MyAssembly.Components.Orders
{
public partial class Checkout : CustomOrderingComponentBase
{
...
[JSInvokable("PlaceOrderAsync")]
public async Task PlaceOrderAsync(string versapayToken)
{
...
I get an error upon DotNet.invokeMethodAsync():
Error: System.ArgumentException: The assembly ‘MyAssembly’ does not contain a public invokable method with [JSInvokableAttribute(“MyAssembly.Components.Orders.Checkout.PlaceOrderAsync”)].
What am I missing?