Timer Helpers 

This control needs reference to MVCControlToolkit.Controls.Core-x.x.x.js.

Timer Helpers  perform  either an Ajax Get to a completely configurable route or a Submit(that may cause either a Get or a Post, either synchronous or ajax, according on how the form is defined) at regular time intervals. They are useful to "poll" the server for updates, and they make easier to design Web Gadgets, or Web Chats. If the polling time is less than the session expiration time, sessions can be kept alive without the need for the user to perform any action.

The Submit type Timer helper is defined as:


public static MvcHtmlString SubmitTimer<VM>(
            this HtmlHelper<VM> htmlHelper, TimeSpan timeInterval, string clientViewModel=null)


If the optional clientViewModel string is not null, a client-side view model with that name is saved before submitting the form.

The GetType Timer is defined as:


public static MvcHtmlString GetTimer<VM>(
            this HtmlHelper<VM> htmlHelper, TimeSpan timeInterval,
           string actionName,
           string targetIdName,
           string controllerName = null,
           object parameters = null,
           string routeName = null,
           string protocol = null,
           string hostname = null,
           string fragment = null,
            InsertionMode mode = InsertionMode.Replace,
            string afterSuccess=null


The timeInterval parameter defines the time interval the Get operation is performed, the targetIdName is the id of the target Html element that will receive the Ajax content, the mode parameter specifies how the new content is inseted in the target node, and the afterSuccess parameter specifies a javascript function that is called with a jQuery object containing the target node as parameter after the new content has been added. All other parameters define the Route as in an usual Action or Ajax link.

Below, a Get Timer is used to get the server Time:


@Html.GetTimer(new TimeSpan(0, 0, 1), "ServerTime", "clock") <div id="clock"></div>

Last edited Jun 22, 2014 at 10:56 AM by frankabbruzzese, version 13


No comments yet.