0

I am building a website using ASP.NET. I need to auto-refresh my webpage according to the database changes every minute. I have been reading about System.Timers but not sure how to implement it on MVC controller. Here's my sample code.

public class HomeController : Controller
{ 
    public ActionResult Index()
    {
        //write the code to refresh page every 1 min

        var appSettings = ConfigurationManager.AppSettings;
        MySQL msql = new MySQL();                          
        List<string> status = msql.SelectList("Select * from table");
        //query database
        return View();
    }
}
NinjaDev
  • 15
  • 1
  • 11
  • There's no way to drive this from the server. You need to drive it [in JavaScript in a timer on the client](http://stackoverflow.com/a/22154172/424129). It's more considerate to the user (and to your server) to do this with AJAX and merely update some HTML dynamically, rather than reloading the whole page. – 15ee8f99-57ff-4f92-890c-b56153 Jun 27 '16 at 18:36
  • This is a task for javascript. – Nikki9696 Jun 27 '16 at 18:36
  • [answered here](http://stackoverflow.com/questions/5396282/auto-refresh-in-asp-net-mvc) You will have to use javascript, but it is pretty simple. – Noah Hall-Potvin Jun 27 '16 at 18:39
  • 1
    @EdPlunkett You can do it from the server, you need to be able to call code on the client from the server. Technology like web sockets make that possible, with [SignalR](http://www.asp.net/signalr) being largely used for these sorts of things. – mason Jun 27 '16 at 18:42
  • @mason Well, Today I Learned. Thank you. Still not the first thing I'd try though. – 15ee8f99-57ff-4f92-890c-b56153 Jun 27 '16 at 18:43
  • How about http://socket.io ? Does a lot of the heavy lifting for you with sockets. – Xander Luciano Jun 27 '16 at 18:50
  • Thank you guys!! I used JavaScript and it worked. – NinjaDev Jun 27 '16 at 19:09

0 Answers0