title: How can i get Javascript Callback in .Net Blazor?
body: <p>Is there a way to add callback to Javascript and get the result in Blazor? Apart from JS Promises.</p>
  
  <p>for example, let say i want to load a file</p>
  
  <p>Javascript Code</p>
  
  <pre><code>window.readFile = function(filePath, callBack) {
      var reader = new FileReader();
      reader.onload = function (evt) {
          callBack(evt.target.result);
      };
      reader.readAsText(filePath);
  }
  </code></pre>
  
  <p>Can i have something like this in Blazor C#</p>
  
  <pre class="lang-cs prettyprint-override"><code>    // read file content and output result to console
      void GetFileContent() {
          JsRuntime.InvokeAsync&lt;object&gt;("readFile", "file.txt", (string text) =&gt; {
              Console.Write(text);
          });
      }
  
  </code></pre>
  
  <p>Or Maybe something like this</p>
  
  <pre class="lang-cs prettyprint-override"><code>    // read with javascript
      void ReadFileContent() {
          JsRuntime.InvokeAsync&lt;object&gt;("readFile", "file.txt", "resultCallbackMethod");
      }
  
      // output result callback to console
      void resultCallbackMethod(string text) {
          Console.Write(text);
      }
  </code></pre>
  
  <p>Thanks</p>