Multiple Countdown Timer using jQuery.
In this blog, I will demonstrate how to set up a countdown timer based on dynamic data. Here, we are going to develop it in MVC framework with C#.
Prepare a dynamic date time list on the server side.
I have used a model named “TimerModel” as we assume that our dynamic timer data will come from the database.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace TimerDemo.Models
- {
- public class TimerModel
- {
- public string Name { get; set; }
- public string ReleaseDateTime { get; set; }
- }
- }
Create one controller and, for now, start preparing a dynamic list which should actually come from the database layer. Here, I have used a static datetime list; you can modify it to get appropriate results. After preparing the listset into "ViewBag.TimerList" take data from Controller to View.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using TimerDemo.Models;
- namespace TimerDemo.Controllers
- {
- public class HomeController : Controller
- {
- public ActionResult Index()
- {
- List<TimerModel> list = new List<TimerModel>();
- list.Add(new TimerModel
- {
- Name = "Display1",
- ReleaseDateTime = Convert.ToString(new DateTime(2018, 11, 25, 00, 30, 00))
- });
- list.Add(new TimerModel
- {
- Name = "Display2",
- ReleaseDateTime = Convert.ToString(new DateTime(2018, 11, 24, 23, 37, 00))
- });
- ViewBag.TimerList = list;
- return View();
- }
- public ActionResult About()
- {
- ViewBag.Message = "Your application description page.";
- return View();
- }
- public ActionResult Contact()
- {
- ViewBag.Message = "Your contact page.";
- return View();
- }
- }
- }
As I stored the list in "ViewBag.TimerList", grab it here on .cshtml page and make it dynamically bound for displaying the labels for the countdown.


Farrukh azadPosted Jul 28, 2022, 6:27 PM
Nice work dear