The New Way to Build with AI! Introducing ReUI — the developer platform for agentic UI with shadcn/ui
Browse ReUI Pro

Js function sometime not work in blazor server


Hello ,
I used metronic 8.1.5 on Blazor Server and my problem is scripts.bundle.js not worked sometimes , I implement JS Import and anything after read docs but my problem still . this problem very important to me, because my development in middle and i can't change my template .

if i write details about my problem , when login into my project ( load layout ) sometime right menu working well and sometimes menu and top widget doesn't work ,when menu not working if i refresh page in browser this problem solved

my code in MainLayout.razor :

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(firstRender)
{
await JS.InvokeAsync<IJSObjectReference>("import", "/assets/js/scripts.bundle.js");
}

}


my code in _Host.cshtml :


<script src="_framework/blazor.server.js" @*autostart="false"*@></script>

<script>
function setTheme(theme, isThemeDark) {
document.getElementsByTagName("body")[0].style.display = "none";
let synclink = document.getElementById("theme");
synclink.href = "_content/Syncfusion.Blazor.Themes/" + theme + ".css";
setTimeout(function () { document.getElementsByTagName("body")[0].style.display = "block"; }, 200);
}
</script>
<script>var hostUrl = "/assets/";</script>
<script src="/assets/plugins/global/plugins.bundle.js"></script>
<script src="/assets/js/scripts.bundle.js"></script>
<script src="/assets/js/Helper.js"></script>

<script src="/assets/plugins/custom/fullcalendar/fullcalendar.bundle.js"></script>


<script src="/assets/plugins/custom/datatables/datatables.bundle.js"></script>

<script src="/assets/js/widgets.bundle.js"></script>
<script src="/assets/js/custom/widgets.js"></script>


Please help me for fix my issue


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)

 
Deleted comment

Nobody can't help me ? this problem is very important in my project



Hi,

Sorry for the late reply.

Please make sure that your component is wrapped with our initialization file Starterkit/Shared/MasterInit.razor.

Or you can call the component additional initialization on your layout file using the code below:


@code {
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(firstRender){
await JS.InvokeVoidAsync("KTComponents.init");
}
}
}


Regards,
Lauris Stepanovs,
Keenthemes Support Team


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
buy metronic keenthemes mega bundle

ReUI

Open-source React components, blocks and templates built on shadcn/ui and Tailwind CSS by Keenthemes.