Skip to content

[Blazor server side preview 7] retrieve complex object from js to c# #12758

@julienGrd

Description

@julienGrd

Hello guys, i meet a problem to retrieve list of object from JS to c#
the initial call is done in c#

var results = await JsRuntime.InvokeAsync<IEnumerable<FileResultJs>>("openFiles", this.Multiselect, this.Filter);

class FileResultJs
    {
        public string Name { get; set; }
        public string Data { get; set; }
    }

i have a method "openFiles" in js wich return a promise, resolved by an array of object wich respect the structure of FileResultJs

var result = [];
//in  a loop
result.push( {
	Name: temporaryFileReader.file.name,
	Data: temporaryFileReader.result.split(',')[1]
});

count++;

if (count == numberFiles) {
	resolve(result);
}

When the promise is resolved with the array , i "go back" to the c#.
If in the js, my array had two elements, i retrieve well an ienumerable of 2 elements, but the two property are null (while they are correctly filled in the JS).

I don't know if what i try to do is possible, and if it's possible, what's the problem in my code ?

thanks for your help !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions