MVC 5从控制器自动刷新 [英] MVC 5 Auto Refresh From Controller

查看:222
本文介绍了MVC 5从控制器自动刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从本地网络服务器加载excel文件,然后每隔5分钟左右刷新一次页面,以防万一该文件已被替换...

I am trying to load a excel file, from a local webserver, then refresh the page every 5min or so, just incase that file has been replaced...

它用于显示时间表,有人会对其进行更新,并且在整个工厂中,页面将显示在监视器上,并且输出将更改...

It is for displaying a schedule, someone will update it and throughout the plant, the page will be displayed on a monitor and the output will change...

我认为这将是非常简单的,我只是将刷新添加到.html文件的标头中并完成操作,但是我认为这仅在使用常规return View()时才有效. ...由于我使用的是重定向,因此不确定是否可以将其添加到标题中...有什么想法吗?

I thought this was going to be super simple, and I would just add a refresh to the header of the .html file and be done, but I think that would only work if I just use the regular return View();... Since I am using Redirect, I am unsure if it is able to add this to the header or not... Any ideas?

这是我添加到控制器中的代码:

Here is the code that I added to my controller:

this.HttpContext.Response.AddHeader("refresh", "5; url=" + Url.Action("time"));
        return Redirect("http://dexweb/scheduler/hunting template.htm");

推荐答案

您似乎正在重定向到某些HTML页面:

It appears that you are redirecting to some HTML page:

http://dexweb/scheduler/hunting_template.htm

在此html内,您可以放置​​ <meta> 标记,以强制其从服务器定期运行:

Inside this html you could put a <meta> tag to force it to refresh from the server at regular intervals:

<meta http-equiv="refresh" content="5">

显然,如今,有更高级的方法可以实现从服务器到客户端的实时推送通知,例如HTML5 WebSockets.

Obviously nowadays there are more advanced ways to achieve real time push notifications from the server to the client such as HTML5 WebSockets.

这篇关于MVC 5从控制器自动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆