简体   繁体   English

在ASP.NET MVC应用程序中异步接收数据

[英]Asyncronously receiving data in an ASP.NET MVC application

I'm looking for the best way to constantly check if data has been sent to our ASP.NET MVC application from a server. 我正在寻找不断检查数据是否已从服务器发送到我们的ASP.NET MVC应用程序的最佳方法。 I would like to asynchronously check for data and update the view when data has been read. 我想异步检查数据并在读取数据后更新视图。

I'm currently using a TcpClient to make a connection, and making the connection in the inherited custom base controller. 我目前正在使用TcpClient建立连接,并在继承的自定义基本控制器中建立连接。 Currently though I have to refresh the page for the updating of the view to take place. 目前,尽管我必须刷新页面以更新视图。

Would there be a proper AJAX solution? 是否会有适当的AJAX解决方案? or do I need to move the connection to the ActionMethod ? 还是我需要将连接移至ActionMethod

要获得完整的解决方案,请使用以下免费库: PokeIn

I would probably use jQuery to query some action at a specified interval and update the page accordingly. 我可能会使用jQuery以指定的时间间隔查询某些操作并相应地更新页面。

I don't know what kind of data you're talking about, but let's look at a simple example. 我不知道您在谈论哪种数据,但让我们看一个简单的例子。 From you're question, it sounds to me like you're trying to do the following: 从您的疑问中,听起来像是您正在尝试执行以下操作:

Suppose you are building Twitter and want to show the newest Tweets on the homepage. 假设您正在构建Twitter,并希望在主页上显示最新的Tweets。 Well, you could have a script that just does a jQuery.GetJSON call to some URL (let's call it twitter.com/latest5tweets) that gets the latest 5 tweets. 好吧,您可能有一个脚本,该脚本仅对某个URL进行了jQuery.GetJSON调用(我们将其称为twitter.com/latest5tweets),该脚本会获取最新的5条tweet。 Then you would have a callback function that would take those tweets and paint them on the screen -- perhaps using some sort of nifty slide effect to remove the older ones from the screen and add the new ones. 然后,您将拥有一个回调函数,该回调函数将这些推文并在屏幕上绘制它们-也许使用某种漂亮的幻灯片效果从屏幕上删除较旧的推特并添加新的推特。

Does that help? 有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM