Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq 如何在MVC中使用Take和Skip函数_Linq_Asp.net Mvc 4_Razor_Asp.net Mvc 5_Asp.net Ajax - Fatal编程技术网

Linq 如何在MVC中使用Take和Skip函数

Linq 如何在MVC中使用Take和Skip函数,linq,asp.net-mvc-4,razor,asp.net-mvc-5,asp.net-ajax,Linq,Asp.net Mvc 4,Razor,Asp.net Mvc 5,Asp.net Ajax,我想在mvc中使用skip and take count加载数据并跳过之前已经附加到视图中的数据 var skipCount = 5; var takeCount = 5; function loadMore() { $(window).bind('scroll', bindScroll); itemCount = takeCount; skipCount += takeCount; setTimeout(function () { getFeed(); },1

我想在mvc中使用skip and take count加载数据并跳过之前已经附加到视图中的数据

var skipCount = 5; 
var takeCount = 5; 

function loadMore() {
  $(window).bind('scroll', bindScroll);
  itemCount = takeCount;
  skipCount += takeCount;
  setTimeout(function () {
    getFeed();
  },100);            
}

function bindScroll() {
  if ($(window).scrollLeft() + $(window).width() > $('.tile-area').width() - 130) {
    $(window).unbind('scroll');
    loadMore();
  }
}

function getFeed() {             
  $.ajax({
    type: "Post",
    url: "/PlanetFeed/PlanetfeedPartial",
    dataType: "html",
    data: { id: planetFeedOwnerId, filterType: filterType, taggedItemGraphId: taggedItemGraphId, itemCount: takeCount, SkipCount: skipCount },      //"feedGraphId=10696",
    success: function (data) {
    if (data === null) {

    } else {
      $('.tile-area-title').html("");
      var div = $('.planetFeed:last');
      div.after(data);
      skipCount += takeCount + 1;
    }                                
  });
}
这是我的控制器,我在这里传递参数

public ActionResult PlanetfeedPartial(Guid id, string filterType, Guid taggedItemGraphId, int itemCount, int SkipCount)
{
  var planetfeedsOrder = from p in db.PlanetFeeds
                         where p.CurrentState != 1
                         join s in searchTag on p.PlanetFeedGraphId equals s.SecondaryTaggedGraphItemId
                         join g in db.Graphs on p.PlanetFeedItemGraphId equals g.GraphID
                         join u in db.UserInfos on p.PlanetFeedPosterId equals u.UserInfoID
                         orderby p.PostDate descending
                         select new PlanetFeedViewModel
                         {            
                           Username = u.FirstName + " " + u.LastName,                                          
                           isRootFeed = p.isRootFeed,
                           PostDate = p.PostDate,
                           CommentCount = g.CountResponses,
                           CountPositiveReactions = g.CountPositiveReactions,
                           CountNegativeReactions = g.CountNegativeReactions,
                           ItemID = g.ItemID,
                           UserLevel = u.UserLevel,
                           CurrentState = p.CurrentState,
                           Address = g.Address
                         };
  return PartialView("_PlanetfeedPartial", planetfeedsOrder.OrderByDescending(p => p.PostDate).Skip(SkipCount).Take(itemCount).ToList());
}
我没有得到正确的数据,每次我在滚动中加载数据时,都会得到不同的数据,顺序不正确,所有数据都没有加载

var planetfeedsOrder = (from p in db.PlanetFeeds
                         where p.CurrentState != 1
                         join s in searchTag on p.PlanetFeedGraphId equals s.SecondaryTaggedGraphItemId
                         join g in db.Graphs on p.PlanetFeedItemGraphId equals g.GraphID
                         join u in db.UserInfos on p.PlanetFeedPosterId equals u.UserInfoID
                         orderby p.PostDate descending
                         select new PlanetFeedViewModel
                         {            
                           Username = u.FirstName + " " + u.LastName,                                          
                           isRootFeed = p.isRootFeed,
                           PostDate = p.PostDate,
                           CommentCount = g.CountResponses,
                           CountPositiveReactions = g.CountPositiveReactions,
                           CountNegativeReactions = g.CountNegativeReactions,
                           ItemID = g.ItemID,
                           UserLevel = u.UserLevel,
                           CurrentState = p.CurrentState,
                           Address = g.Address
                         }).orderby(o=>o.id).skip(100);

跳过100然后显示您的数据,并根据您想要的序列数据的任何id或字符串创建顺序。

我建议您尝试使用参数进行跳过/获取。您的代码是一堆方法,它们相互调用,并在多个位置更改全局变量。我无法在脑海中调试它。@GertArnold您能给我一些提示吗?我的id是GUID。它会做一些更改,或者可以正常工作?GUID不是默认排序的,所以当在db中插入记录时,这里有任何日期吗?是的,使用p.Postdate,但有一件事页面加载时会跳过前100个值?按降序(o=>o.Postdate)。取(100); 这将返回您网格中的前100条记录…您收到我的要求了吗..我希望在视图中显示前5个值,然后显示下5个值,依此类推。。因此,可以跳过预加载的最后一个值/