Not possible to call JavaScript method #53161
Labels
area-blazor
Includes: Blazor, Razor Components
✔️ Resolution: Answered
Resolved because the question asked by the original author has been answered.
question
Status: Resolved
Is there an existing issue for this?
Describe the bug
This is basically a repost of this report: dotnet/AspNetCore.Docs#30311
According to documentation it should be possible to call JS method (not function).
The documentation: https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/call-javascript-from-dotnet?view=aspnetcore-7.0 or https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/?view=aspnetcore-7.0#javascript-interop-calls-without-a-circuit
I fail to see how they address the issue of calling a JS method (instance one, non-static), or if not possible -- how to dereference obtained reference. The only scenarios I found is disposing JS reference and calling a function within module.
Consider such case:
If this is not possible, it would be good to mention it in documentation. If it is possible, small example would be helpful.
The stopping step for me is (3). I tried two approaches -- calling a method, like here, JS part:
and C#:
This gives me an error:
The second approach would be to call a function via JsRuntime and pass one parameter to it -- obtained reference (
instance
in the above code). However here I have no idea how to dereference it on JS side -- I have the reference, and I need to obtain JS object out of it, in other words "undo" whatcreateJSObjectReference
did.Lack of documentation about the proper method call is troublesome for me here.
cc: @guardrex dotnet/AspNetCore.Docs#30311
Expected Behavior
Ability to call a JS method.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
7.0.400
Anything else?
No response
The text was updated successfully, but these errors were encountered: