1

I have a problem with the data returned from C # to JS. CefSharp configuration:

        Cef.Initialize();
        CefSharpSettings.WcfEnabled = true;
        CefSharpSettings.LegacyJavascriptBindingEnabled = true;
        browser = new ChromiumWebBrowser("")
        {
            Dock = DockStyle.Fill
        };
        this.Controls.Add(browser);
        SM = new ScriptManager(browser);
        browser.RegisterAsyncJsObject("external", SM); //"Support" for C# methods from JavaScript

I am trying to call the C# method from JS:

...
var UserID_array = window.external.loadUsrIDs(usr_names); //usr_name -> array of user names

In C# the declaration of method is as follows:

class ScriptManager
{
  ...

  public int[] loadUsrIDs(object usr_names = null) //by default if usr_names == null then return all user IDs
  {
    ...//reading the database

   return id_users.ToArray();   //from List<int> to int[]
  }

}

Unfortunately, instead of the Int array (int[]) I always get the following value ([object Promise]) - test code:

var UserID_array = window.external.loadUsrIDs(usr_names);
alert(UserID_array); //alert - only for tests

//Alert function always return value: **[object Promise]**

How do I get access to the returned data by C# method in JS?

Regards

Marcin

5

2 Answers 2

0

try using

var UserID_array = await window.external.loadUsrIDs(usr_names);
0

You need to wait for the response.

Once you have called your C# function, assign the results to a variable (like you already have done).

Then use the then(success,failure) feature to consume the data.

var UserID_array = window.external.loadUsrIDs(usr_names);

UserID_array.then(
    function(result) {
        doSomethingWithYourData(result);            
    }, function (err) { 
        console.log(err); 
    });

This makes your page far more responsive allowing the UI to continue to respond to your users while waiting for your data.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.