简体   繁体   中英

Reloading a partial view when a function in the view completes?

I've made a scrolling ticker to keep track of live stats as they enter a database, it's in its own partial view, but I'm wondering if its possible to refresh the div with new information when the scrolling function completes in the partial view so that new data is displayed in a timely manner without having to reload the whole page.

I call it simply with :

 @Html.Partial("Ticker", Model)

Where Model is the data used in the view.

Example of what the ticker looks like: http://www.smoothdivscroll.com/runningTicker.html

Implement the Ticker action:

    public PartialViewResult Ticker(int param) {
        TickerModel model = new TickerModel();
        // TODO: fill the model 
        return PartialView(model);
    }

and then invoke it form the JavaScript function:

function reload() {
   $.ajax({
            url: '@Url.Action("Ticker")',
            data: { param: .... },
            success: function (data) {
                $("#TickerDiv").html(data);
            }
        });
}

Instead of

@Html.Partial("Ticker", Model) 

use

<div id="TickerDiv">
    @Html.Action("Ticker", new { param = .... })
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM