简体   繁体   中英

How to store return value from Razor Syntax foreach loop back out to JavaScript

var intervals = [];
        //
        //Load each widget
        //
        @foreach (var widget in Model.Widgets.OrderBy(p => p.OrderSequence).ThenBy(p => p.Title).ToList())
        {
            @:loadWidget("@widget.WidgetId", "@widget.AjaxUrl");
            if (widget.RefreshSeconds > 0)
            {
               @:setupWidgetAutoRefresh("@widget.WidgetId", "@widget.AjaxUrl", @widget.RefreshSeconds);
            }
        }

I need to store the return value from the setupWidgetAutoRefresh method into my Javascript intervals array. Is it possible for me to do so? How would I go about completing such a task?

var intervals = [];
//
//Load each widget
//
    @foreach (var widget in Model.Widgets.OrderBy(p => p.OrderSequence).ThenBy(p => p.Title).ToList())
{
    @:loadWidget("@widget.WidgetId", "@widget.AjaxUrl");
    if (widget.RefreshSeconds > 0)
    {
        @:intervals.push(setupWidgetAutoRefresh("@widget.WidgetId", "@widget.AjaxUrl", @widget.RefreshSeconds));
    }
}

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