Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
How to reference local JS modules in Blazor components?

On Dotnetconf two weeks ago I heard it is now possible to include local Javascript files in Blazor components. That sounds very interesting. I guess the approach is still to use JSIniterop and reference the module file.

BUT how do you reference the JS file ??? I have tried all possible creative variants but so far without success.

I am surprised to Google everywhere but find no guides or sample yet on this. All hints are appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can create .js code file next to .razor.cs file and load that file in runtime. It's described here. Also I found presentation of this feature here and github repo here.

Let's say that you have ComponentA with ComponentA.razor, ComponentA.razor.cs and ComponentA.razor.js files in Pages folder. You can load this module during component's initialization like so:

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

private IJSObjectReference module { get; set; }

protected override async Task OnInitializedAsync()
{
    module = await JS.InvokeAsync<IJSObjectReference>("import", "./Pages/ComponentA.razor.js");
}

But if your component is defined in a component library project then you have to use different file path. For example if your project is named AppComponents then this path would be ./_content/AppComponents/ComponentA.razor.js.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda