Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Return a list of JSObjectReference in Blazor using JS Interop

$
0
0

Is it possible to return a list of object references from JS to C#? Currently I do return a list of objects (THREE.js objects) though I am unable to deserialize it into a C# IList or array to get separate IJSObjectReference instances on .NET side. I simply get one IJSObjectReference (logically possible) which is a reference to the JS array itself.

Anyone know if it is possible to deserialize a JS Array into a C# array/list/collection and in this case, for it to contain JSObject references?

This is basically what I am trying to do

const myJsFunc () = () => {    ....    return [someJsObject, anotherJsObject]}

C# side

var objectReferencesArray = js.Invoke<IJSInProcessObjectReference[]>("myJsFunc", ...);

or

var objectReferencesArray = js.Invoke<IList<IJSInProcessObjectReference>>("myJsFunc", ...);

neither work. I am only able to get ONE object ref which is for the array itself.

EDIT: Still interested in hearing suggestions on this but as an update I can say that I chose to simply return the list as its own IJSInProcessObjectReference and then when I pass it back to JS, destruct it and handle it that way.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>