Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda