1

I have a graph that keeps getting input data from users, so I just need this page to reload to show new information from time to time. The problem is that when using setTimeOut the system is reloading the whole page, including _Layout, which is the main page, where there is a side bar.

_Layout

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="RVE Online">

    <body>
    <div class="page-wrapper chiller-theme toggled">
        <a id="show-sidebar" class="btn btn-sm btn-dark" href="#">
            <i class="fas fa-bars"></i>
        </a>
        <nav class="navbar navbar-light fixed-top  flex-md-nowrap p-0 shadow" style="background-color: #dadbed;">
            <a class="navbar-brand   " href="#"> </a>

            <ul class="navbar-nav px-3">
                <li class="nav-item text-nowrap">
                </li>
            </ul>
        </nav>
        <nav id="sidebar" class="sidebar-wrapper">
            <div class="sidebar-content">
                <div class="sidebar-brand text-center">
                    <a href="#"></a>
                    <div id="close-sidebar">
                        <i class="fas fa-times"></i>
                    </div>
                </div>              
                <!-- sidebar-header  -->
                <!-- sidebar-search  -->
                <div class="sidebar-menu">
                    <ul>
                        <li class="header-menu">
                            <span>Painel Operacional</span>
                        </li>
                        @if (User.IsInRole("Administrator"))
                        {
                            <li class="sidebar-dropdown">
                                <a href="#">
                                    <i class="fa fa-users"></i>
                                    <span>Usuários</span>
                                </a>

                                <div class="sidebar-submenu">
                                    <ul>
                                        <li>
                                            <a href="@Url.Action("Index", "AdminUser")" onclick="trytoredirect()">
                                                Listagem
                                                <span class="badge badge-pill badge-success">Pro</span>
                                            </a>
                                        </li>
                                        <li>
                                            <a href="@Url.Action("ViewAllRoles", "AdminUser")" onclick="trytoredirect()">
                                                Editar perfils
                                                <span class="badge badge-pill badge-success">Pro</span>
                                            </a>
                                        </li>
                                    </ul>
                                </div>

                            </li>
                        }
                        @if (User.IsInRole("Administrator") || (User.IsInRole("OLNF")) || (User.IsInRole("OLS")))
                        {
                            <li class="sidebar-dropdown">
                                <a href="#">
                                    <i class="fa fa-ship"></i>
                                    <span>Embarcações</span>
                                </a>
                                <div class="sidebar-submenu">
                                    <ul>
                                        <li>
                                            <a href="@Url.Action("Index", "Barcos")" onclick="trytoredirect()">
                                                Listagem

                                            </a>
                                        </li>
                                        <li>
                                            <a href="@Url.Action("ListarEstoque","Barcos")">Consultar Estoque</a>
                                        </li>
                                    </ul>
                                </div>
                            </li>
                        }

                <!-- sidebar-menu  -->
            </div>
            <!-- sidebar-content  -->

        </nav>
        <!-- sidebar-wrapper  -->
        <main class="page-content">
            <div class="container-fluid">
                @RenderBody()

            </div>
        </main>
        @Html.Partial("_Footer")
    </div>
    <!-- page-wrapper -->

    @Scripts.Render("~/bundles/bootstrap")
    @Scripts.Render("~/bundles/LayoutPage")
    @Scripts.Render("~/bundles/Canvas")
    <script src=" @Url.Content("~/scripts/sistema.js")"></script>

    @RenderSection("scripts", false)


    <div id="modalContainer">
    </div>

</body>
</html>

My idea was to call the controller from time to time, something like that ...

 <script type="text/javascript">
    $(doument).ready(function(){
       setTimeout(function () {
            window.location.reload(1);}, 10000)
            .load("@Url.Action("Index", "Home")");  
        });
    });
   //i know the code is wrong, just a idea
</script>

My home view

<div class="container">
    <div id="chartContainer" style="height: 400px;"></div>
</div>

<script>
window.onload = function () {
    var timeInMs = Date.now();

var chart = new CanvasJS.Chart("chartContainer", {
    theme: "light2", // "light1", "light2", "dark1", "dark2"
    exportEnabled: true,
    animationEnabled: true,

    title: {
        text: "Relação de Apontamentos x Códigos Operacionais " + " na data de "+ CanvasJS.formatDate(new Date(timeInMs)),
        fontSize: 21

    },
    verticalAlign: "center",
    horizontalAlign: "center",
    width:1100,
    data: [{
        type: "pie",
        startAngle: 160,
        toolTipContent: "<b>{label}</b>: {y}%",
        indexLabel: "{label} - {y}%",
        dataPoints: @Html.Raw(ViewBag.DataPoints)
    }]
});
chart.render();

        }

        $(document).ready(function () {
            setTimeout(function () {
                window.location.reload(1);
            }, 10000); 
        });
</script>

I currently have this script on the Index page, but as I said, it reloads the _Layout page along, as I would load this page on my own from time to time.

Jhensen
  • 71
  • 7

1 Answers1

0

So you wish to reload a specific part of the page? I would sugest looking at this function since you seem to be using jQuery: .load().

Here is an other answer to this question Refresh Part of Page

Achtung
  • 682
  • 3
  • 16