I have Blazor Server Side app, where I have added JavaScript and CSS Libraries for Metronic Bootstrap Template.
The template is fully loaded when I run the app, but the JavaScript is not responding.
For example when I click on Side Menu (Arrow Icon) or Expand the Lists, or click on User Profile Drop down, all those sections are not working.
But when I comment out line, Blazor Server Library (blazor.server.js
) template starts working, but other Blazor Components don't work properly (e.g. Counter).
In _Host.cshtml
file Head
Section added following CSS References:
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700" />
<link href="assets/plugins/custom/fullcalendar/fullcalendar.bundle.css" rel="stylesheet" type="text/css" />
<link href="assets/plugins/global/plugins.bundle.css" rel="stylesheet" type="text/css" />
<link href="assets/css/style.bundle.css" rel="stylesheet" type="text/css" />
In Body
Section added following JavaScript References.
<script src="_framework/blazor.server.js"></script>
<script src="./assets/plugins/global/plugins.bundle.js"></script>
<script src="./assets/js/scripts.bundle.js"></script>
<script src="./assets/plugins/custom/fullcalendar/fullcalendar.bundle.js"></script>
<script src="./assets/js/custom/widgets.js"></script>
<script src="./assets/js/custom/apps/chat/chat.js"></script>
<script src="./assets/js/custom/modals/create-app.js"></script>
<script src="./assets/js/custom/modals/upgrade-plan.js"></script>
I also tried the following methods, but nothing is working. Looks like Blazor Server App is Rendering before these JavaScript files are loaded into DOM. How Can I load these Scripts and work them properly. Any help will be much appriciated.
<script src="_framework/blazor.server.js" autostart="false"></script>
<script>
Blazor.start().then(function () {
var customScript = document.createElement('script');
customScript.setAttribute('src', scriptURLs);
document.head.appendChild(customScript);
});
const scriptURLs = [
"./assets/plugins/global/plugins.bundle.js",
"./assets/js/scripts.bundle.js",
"./assets/plugins/custom/fullcalendar/fullcalendar.bundle.js",
"./assets/js/custom/widgets.js",
"./assets/js/custom/apps/chat/chat.js",
"./assets/js/custom/modals/create-app.js",
"./assets/js/custom/modals/upgrade-plan.js",
// ...
];
</script>
In my MainLayout.razor
@inherits LayoutComponentBase
@inject IJSRuntime JSRuntime
<div class="d-flex flex-column flex-root">
<div class="page d-flex flex-row flex-column-fluid">
<MainSidebar />
<div class="wrapper d-flex flex-column flex-row-fluid" id="kt_wrapper">
<MainHeader />
@Body
<MainFooter />
</div>
</div>
</div>