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

102
Visualizações
How to Avoid Refreshing the Page when Clicking on the Side Menu item

I have a Side Menu, each Menu item is a ViewComponent, when I click on the item the entire page is reloaded, I've tried using JavaScript, "prevent Default OnClick" on the Link, but when doing this the Click gets crash, I would just like the Content was render to the Side.

My _Layout :

<!-- sidebar menu -->
<div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
    <div class="menu_section">
        <ul class="nav side-menu">
            <vc:menu />
        </ul>
    </div>
</div>

My ViewComponent :

<li>
    <a><i class="fa fa-edit"></i> @menu.Title <span class="fa fa-chevron-down"></span></a>
    <ul class="nav child_menu">
        @foreach (var submenu in menu.Items)
        {
            <li><a href="@submenu.Route">@submenu.Title</a></li>
        }
    </ul>
</li>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I think you need to preventDefault by using this code:


<a href="@submenu.Route" (click)="$event.preventDefault()"></a>
about 4 years ago · Juan Pablo Isaza Relatório

0

Maybe you wanna this feature?

In the cshtml file, you remove the href feature of tag and using ajax to get the page content.

<div><a id="btn1" href="#">btn1</a><a id="btn2" href="#">btn2</a></div>
<div id="center" style="width:800px;height:500px;background-color:#eee"></div>

<script>
    $("#btn1").click(function () {
        $.ajax({
            url: "https://localhost:44372/home/getPartialViewOne",
            type: "get",
            success: function (data) {
                $("#center").html("").append(data);
            }
        });
    });

    $("#btn2").click(function () {
        $.ajax({
            url: "https://localhost:44372/home/getPartialViewTwo",
            type: "get",
            success: function (data) {
                $("#center").html("");
                $("#center").html(data);
            }
        });
    });
</script>

And the controller should create corresponding methods which return page view

public IActionResult getPartialViewOne() { 
            return new PartialViewResult
            {
                ViewName = "Test1Partial"
            };
        } 
        
        public IActionResult getPartialViewTwo() { 
            return new PartialViewResult
            {
                ViewName = "Test2Partial"
            };
        }
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