I have Blazor Server Web App Project that contains this default javascript link:
<script src="_framework/blazor.server.js"></script>
When I remove the link, my other js files load correctly, but if I add it back then they do not load. It does not matter if I add blazor.server.js before or after my js links.
HOW TO RECREATE MY SCENARIO:
- Create default Blazor Server Web App
- Add a new
demo.jsfile towwwrootand enter this js code:
$(document).ready(function () {
$("#clickme").on("click", function () {
alert("Handler for the 'Click Me' button is called.");
});
});
Add
demo.jsto_Host.cshtmllike this:<script src="~/demo.js"></script>Create a button in
/Indexor/Counterand add:id="clickme"Make sure that
<script src="_framework/blazor.server.js"></script>is present in_Host.cshtml
Buid and Run.
Result 01:
- The Blazor Server Web App will run but when you click the button, js code is not called.
Now, remove <script src="_framework/blazor.server.js"></script>, build and run.
Result 02:
- The Blazor Server Web App will run and when you click the button, js code is called correctly.
I want to include <script src="_framework/blazor.server.js"></script> and other js files and make them work.
What could be the problem?
I am using:
- Visual Studio IDE 2022
- Blazor Server Web App
- .NET 7