© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
로크소르 - RoxxorXx

❔ Blazor Server .net7 js injection

Hey, i'm currently leaning blazor,

i've seen that js can be isolated as css file but i have to do
`cs
@code
{
    private IJSObjectReference module;
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        Console.WriteLine("index");
        module = await JS.InvokeAsync<IJSObjectReference>("import", "./Pages/Index.razor.js");
    }
}
`cs
@code
{
    private IJSObjectReference module;
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        Console.WriteLine("index");
        module = await JS.InvokeAsync<IJSObjectReference>("import", "./Pages/Index.razor.js");
    }
}


so that mean for every component that i want to use i need to redo that.
I see the way to use an @inherit and doing a generic class to do that but i want to figure out if maybe there is a better way to "inject" js when ther eis a component.razor.js file available
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Blazor Server
C#CC# / help
2y ago
Hosting Blazor Server
C#CC# / help
14mo ago
Blazor Wasm with blazor server or API
C#CC# / help
3y ago