Invoking Static Methods from a Class
- The static method identifier
- The name of the assembly containing the class and static method
- Any associated arguments
The .Net method must be:
- A public static method
- The method must be decorated with the [JSInvokable] attribute
The array is then logged to the developers console as shown in Figure 8 below.
Invoking Instance Methods of a Class
In addition to calling static class methods, you can also invoke class instance methods. In order to invoke an instance method you have to:
Which in-turn outputs the string “Hello Blazor!” which is then logged to the browsers developer console as shown below in Figure 12.
The rejected promise is then caught in the try catch block of the runPromiseFunction() function. The catch error handler then uses our C# DotNetObjectReference PromiseHandler will invoke the PromiseHandler.SetError() method to raise an exception See Figure 26. This exception is then caught in the RunMethodThatGeneratesAnError() page method, see Figure 21 and 22. The exception handler in this method then surfaces the error to be displayed on the page.
Figure 27 and 28 show the before and after clicking the ‘Run promise to get result (this time the promise rejects and returns an error)’ button.