Reputation: 1934
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.
Upvotes: 0
Views: 690
Reputation: 327
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>
Upvotes: 1