JavaScript to .NET
What about the other way around? I would argue that calling .NET code from JavaScript isn’t a very common scenario, and if we find ourselves in that scenario, we might want to think about what we are doing.
As Blazor developers, we should avoid using JavaScript as much as possible.
I am not bashing JavaScript in any way, but I see this often happen where developers kind of shoehorn what they’ve used before into their Blazor projects.
They are solving things with JavaScript that are easy to do with an if
statement in Blazor. So, that’s why I think it’s essential to think about when to use JavaScript and when not to use JavaScript.
There are, of course, times when JavaScript is the only option, and as I mentioned earlier, Blazm
uses communication both ways.
There are three ways of doing a callback from JavaScript to .NET code:
- A static .NET method call
- An instance method call
- A component instance...