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

262
Visualizações
Calling javascript function from razor page's code

Considering that I have progress bar coded from this website https://www.geeksforgeeks.org/creating-progress-bar-using-javascript/.

I have one razor page with cshtml format and one razor page's code with cshtml.cs. Let's assume I have Index.cshtml and Index.cshtml.cs.

Index.cshtml

<style>
    #Progress_Status {
        width: 50%;
        background-color: #ddd;
    }

    #myprogressBar {
        width: 0%;
        height: 35px;
        background-color: #4CAF50;
        text-align: center;
        line-height: 32px;
        color: black;
    }
</style>

<div id="Progress_Status">
    <div id="myprogressBar"></div>
</div>

<script>
    function update(width) {
        var element = document.getElementById("myprogressBar");
        var identity = setInterval(scene, 10);
        function scene() {
            if (width >= 100) {
                clearInterval(identity);
            } else {
                width++;
                element.style.width = width + '%';
            }
        }
    }
</script>

Index.cshtml.cs

public async void OnGet()
{
    var progress = new Progress<int>(percent =>
    {

        //Do something
    });
    await Task.Run(() => TestFunction(progress));
}

public void TestFunction(IProgress<int> progress)
{
    int LoopCount = 1;
    while (LoopCount <= 100) 
    {
        if (progress != null)
        {
            progress.Report(LoopCount);
        }
        LoopCount += 1;
    }
}

My question is .. considering that I have a progressbar coded with the sample link above. How can I call the update function that exist in javascript in Index.cshtml.cs?

The usual upload file async that can update the progress bar exists in ASP.NET Core (stackoverflow or other website) does not work as this application does not involve with uploading file.

If this way of calling javascript function to update the progressbar is not recommended, is there any alternative way to do it?

about 4 years ago · Juan Pablo Isaza
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