如何更新数据库中的新数据视图

时间:2013-11-22 12:53:57

标签: javascript jquery asp.net-mvc json asp.net-mvc-4

<script type="text/javascript">
    $(document).ready(function () {
    function getPlanetFeeds() {
       $("#planetFeedsDiv").load('/PlanetFeed/GetPlanetFeeds', function (data) {
       });

    var refreshPartial = setInterval(function () { getPlanetFeeds() }, 3000);
    function myStopFunction() {
       clearInterval(refreshPartial);
    }

 <div id="planetFeedsDiv">
 </div>

我正在尝试从数据库中获取Feed,但问题是如果我上传视频而不是刷新而无法连续观看视频 如果我删除此时间间隔功能或增加时间间隔

var refreshPartial = setInterval(function () { getPlanetFeeds() }, 3000);
function myStopFunction() {
   clearInterval(refreshPartial);
}

比我无法定期更新饲料

我正在从控制器获取星球,如下所示

public ActionResult GetPlanetFeeds()
{
    var planetfeedsOrder = from a in db.PlanetFeeds
                            join c in db.Graphs
                            on a.PlanetFeedItemGraphId  equals c.GraphID
                            join u in db.UserInfos
                            on c.ItemUserID equals u.UserID
                            orderby a.PostDate descending
                           select new UserInfoViewModel
                           {
                               FirstName = u.FirstName,
                               LastName = u.LastName,
                               UserID = u.UserID,
                               AvatarURL = u.AvatarURL,
                               GraphItemDescription = c.GraphItemDescription,
                               GraphItemURL = c.GraphItemURL,
                               GraphID = c.GraphID,
                               ItemType = c.ItemType,
                               ItemUserID = c.ItemUserID,
                               GraphItemTitle = c.GraphItemTitle
                           } ;
    return PartialView("_PlanetFeeds", planetfeedsOrder.ToList());
}

1 个答案:

答案 0 :(得分:1)

通过在数据库中搜索来检查旧计数和更新值,并在NewDataCount大于旧数据时调用getPartial方法