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

219
Vistas
Migration from .cshtml to *.razor

It's possible to use Url.Content and scripts in DummyPage.razor? It's necessary to implement the code from DummyPage.cshtml to DummyPage.razor.

@page "/apidocumentation"
<div class="container-flex">
    <div class="col-lg-12 control-section">
        <div class="content-wrapper">
            <div class="row">
                <rapi-doc spec-url="@Url.Content("doc/api/dummy.json")"></rapi-doc>

                <section Scripts>
                    <script src="@Url.Content("lib/rapidoc/dummy.js")"></script>
                </section>
                
            </div>
        </div>
    </div>
</div>

@code {

}

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

You need inject IJSRuntime for JS. It allows to load JavaScript code to your component.

If your JS function has a specific name, you can call with these function: InvokeAsync/InvokeVoidAsync.

Example:


Add script tag in your _Host.cshtml (P.S. ~ is equal to your wwwroot folder)

...
<script src="~/js/myJS.js"></script>
<script src="_framework/blazor.server.js"></script>

myJS.js

function MyScript(name) {
    return "Hello " + name;
}

Test.razor

@page "/test"
@inject IJSRuntime JS

<p id="myId">@Text</p>
<button @onclick="OnClick">Submit</button>

@code {
    private string Text { get; set; }

    private async void OnClick()
    {
        var exampleText = "World!";
        try
        {
            Text = await JS.InvokeAsync<string>("MyScript", exampleText);
        }
        catch(JSException ex)
        {
            Text = ex.Message;
        }

        StateHasChanged();
    }
}

Example after pushed the button: Example output with JS

If your JS script use a function onload (for example), you could override and use the OnAfterRenderAsync function.

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        //invoke only one time, after your component is loaded
        if (firstRender)
        {
            await JS.InvokeVoidAsync("onload");
        }
        
    }

I don't know rapi-doc, maybe you could pass the json through backend with a variable.

about 4 years ago · Santiago Gelvez 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