Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor Web App doesnt seem to let JavaScript work in project, why?

$
0
0

i used to be able to do the following

  • start a blazor web server project

  • Add a JS Folder inside wwwroot and create my js file

  • Link the file using script src="JS/Mapbox_Menu.js

  • inject IJSRuntime into page

    [Inject] public IJSRuntime JS { get; set; }

  • Call the function

    protected override Task OnAfterRenderAsync(boolfirstRender){JS.InvokeAsync("Testing");return base.OnAfterRenderAsync(firstRender);}

and it would work perfectly


now it does not. when i select Blazor Web App with the following settings;

.net8, Auth-None, Configure for HTTPS - True, Interactive Render Mode - Server, Interactivity Location - Per page/component, Include sample pages - false, Do not use top-level statements - true, Enlist in .Net aspire orchestration - false

the i do the same setup for my js files as stated above. it loads but nothing is being called from the js file. i'll list the steps below and file contents below.

i added the script tags for my js file in the app.razor body tag under the and under the on my page inside the code section im doing the following:

[Inject] public IJSRuntime JS { get; set; }protected override Task OnAfterRenderAsync(bool firstRender){    JS.InvokeAsync<bool>("Testing");    return base.OnAfterRenderAsync(firstRender);}

and this does not work (however, it works perfectly inside a .net 6 blazor web server project). does .net8 Blazor no longer support JS??


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>