Register Log in

Passing reference object from js to C# and back

Posted 52 days ago by manikanta
1
I want to pass object by reference from JavaScript to C# and back. Is there any way to do this.

i am using the below code to call the javascript function.

[JSInvokable("ExecuteJS")]
public static async Task<object> ExecuteJS(string value)
{
var result = await jsRuntime.InvokeAsync<object>("somefunction");

//Do some modification

return result
}
  • 1

    Maybe someone else will chime in, but I'm guessing you'll probably want to serialize it with something like Newtonsoft.Json, pass it as a string, then deserialize it in the JavaScript file with JSON.parse().

    Here's a blog post by Chris Sainty about working with JavaScript Interop, in case it helps: https://chrissainty.com/using-javascript-interop-in-razor-components-and-blazor/

    Posted 51 days ago by selliott
  • 0

    Thank u Selliott.

    Posted 37 days ago by manikanta

Post a Reply

You must be logged in to add a new post.
An error has occurred. This application may no longer respond until reloaded. Reload 🗙