0

How can i call javascript in a blazor server application? I am trying to follow this document

http://www.binaryintellect.net/articles/aede436b-4c57-4551-a7b4-a005f2aed499.aspx

On my ui.razor file i created the following code

@inject IJSRuntime JsRuntime;
...
private async void callWidgetApplication()
{
    var fetched = await JSRuntime.InvokeAsync<bool>("fetchComponenent", DotNetObjectReference.Create(this));
}

I create a file on my wwwroot call Widget.js. this is what i have for the moment

function fetchComponenent() {
    return true;
}

But i keep getting an error on my invokeasync.

CS1503  Argument 2: cannot convert from 'Microsoft.JSInterop.DotNetObjectReference<InfoAccessBlz.Pages.InfoAccess>' to 'object?[]?'

The whole reason in using javascript is to call an other website using ajax. So maybe if there is a better way, this is not an api, but its to retrieve an html site.

1 Answer 1

1
 await JsRuntime.InvokeVoidAsync("fetchComponenent");

Your JavaScript Function doesn't accept any parameter and add the JavaScript file to the _Host.cshtml like this

<script src="~/Widget.js"></script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.