0

everyone. I am using NET Framework 4.8.1. I'm having a problem when I try to reload a view, it's like it doesn't delete my javascript and going to reload it sends all the constants to me in error.

I attach the code below.

HTML:

<div class="row bg-dark">
    <div class="col-2" style="margin-top: 1%;">
        <div class="row">
            <div class="row">
                <h2>Menu</h2>
            </div>
            <hr>
            <div class="row">
                <ul class="nav nav-pills flex-column mb-auto">
                    <li>
                        <a onclick="LoadComponents()" id="btnDashboard" class="nav-link text-white active">
                            Dashboard
                        </a>
                    </li>
                    <li>
                        <a href="#" id="btnNotification" class="nav-link text-white position-relative">
                            Notification <span id="spanCount" style="color: red;"></span>
                        </a>
                    </li>
                    <li>
                        <a href="#" class="nav-link text-white">
                            Logout
                        </a>
                    </li>
                </ul>
            </div>
            <hr>
        </div>
    </div>

    <div class="col-10" style="margin-top: 1%;" id="divLoadComponent">
        
    </div>
</div>

Js:

function LoadComponents(){        
    $('#divLoadComponent').empty()

    var url = '@Url.Action("Accounts", "Home")'
    $('#divLoadComponent').load(url)
}

It behaves as if the script is not deleted with $('#divLoadComponent').empty() and as a result I reload all the html with the script each time and the constants fail, in addition to the fact that the alerts are repeated for each time I click on "Dashboard".

  • 1
    If there are ` – Pointy Jul 20 '23 at 15:12
  • @Pointy Exactly! What do you recommend I do? – user22259345 Jul 20 '23 at 15:30
  • Well, seems like the best thing to do is avoid having ` – Pointy Jul 20 '23 at 16:19
  • @Pointy Thanks! I change the logic of my js file and now it's work. – user22259345 Jul 21 '23 at 15:58

0 Answers0