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

363
Visualizações
How to open and close a blazor page using Onclick

I have a button where I open a blazor page currently I use the css display changing between none and block.

But I want to change the way this works, what I thought I'd add to open the page when I click on the button and close when I click on the other one

The opened razor page must open inside the main window.

I use the button as follows:

<svg class="Mybutton" viewBox="0 0 50 50" @onclick="() => OpenConf()">
    ...
</svg>


void OpenMenu() {
    SRuntime.InvokeAsync<string>("OpenConf");
}


function OpenConf() {
    document.getElementById("navi").style.display = "block";
}

Is there any way to open and close the page created in a razor file?

To be clearer, an example.

I have the main window and in that window I have a Config button.

When I click on this button it opens the razor file with the code for this page and when I click on the button inside this page it closes

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Good start.

One thing to keep in mind when writing with Blazor is that you very rarely need JS, which can help you reach a solution.

Firstly - remember that Blazor detects state and will update the page accordingly. Hence, we can create a bool to remember if the page should be shown/hidden.

@code
{
   private bool _pageShown = true;
}

Now lets create a button to toggle this Boolean

<button @onclick="() => _pageShown = !_pageShown">Toggle</button>

Note that this is a lambda function, because this is an EventHandler.

Finally, lets add an if statement

@if (_pageShown)
{
   <p>
      Content we might want to show, but we also might want to hide this...
   </p>
}
about 4 years ago · Juan Pablo Isaza 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